From 7278a264b2277cad1c03f7f5b2b5068088582d81 Mon Sep 17 00:00:00 2001 From: smiley Date: Mon, 8 Feb 2016 17:43:44 +0100 Subject: [PATCH] more tests --- phpunit.xml | 3 +- tests/Data/DataTest.php | 62 +++++++++++++++++++++++++++++++++++++++++ tests/QRCodeTest.php | 32 +++++++++++++++++++++ tests/UtilTest.php | 5 +++- 4 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 tests/Data/DataTest.php create mode 100644 tests/QRCodeTest.php diff --git a/phpunit.xml b/phpunit.xml index d395b9b9b..25e82cf68 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -17,8 +17,7 @@ - tests/BitBufferTest.php - tests/UtilTest.php + ./tests/ diff --git a/tests/Data/DataTest.php b/tests/Data/DataTest.php new file mode 100644 index 000000000..8c45906ea --- /dev/null +++ b/tests/Data/DataTest.php @@ -0,0 +1,62 @@ + + * @copyright 2015 Smiley + * @license MIT + */ + +namespace chillerlan\QRCodeTest\Data; + +use chillerlan\QRCode\BitBuffer; +use chillerlan\QRCode\QRConst; +use chillerlan\QRCode\Data\AlphaNum; +use chillerlan\QRCode\Data\Byte; +use chillerlan\QRCode\Data\Kanji; +use chillerlan\QRCode\Data\Number; + +class DataTest extends \PHPUnit_Framework_TestCase{ + + /** + * @var \chillerlan\QRCode\BitBuffer + */ + protected $bitBuffer; + + /** + * @var \chillerlan\QRCode\Data\QRDataInterface + */ + protected $module; + + public function bitProvider(){ + return [ + [QRConst::MODE_NUMBER, Number::class, '1234567890'], + [QRConst::MODE_ALPHANUM, AlphaNum::class, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'], + [QRConst::MODE_BYTE, Byte::class, '#'], + [QRConst::MODE_KANJI, Kanji::class, '茗荷'], + ]; + } + + protected function setUp(){ + $this->bitBuffer = new BitBuffer; + } + + /** + * @dataProvider bitProvider + */ + public function testMode($mode, $class, $data){ + $module = new $class($data); + $this->assertEquals($mode, $module->mode); + } + + /** + * @dataProvider bitProvider + */ + public function testWrite($mode, $class, $data){ + $module = new $class($data); + $module->write($this->bitBuffer); + // todo... + } + +} diff --git a/tests/QRCodeTest.php b/tests/QRCodeTest.php new file mode 100644 index 000000000..a509fa3a2 --- /dev/null +++ b/tests/QRCodeTest.php @@ -0,0 +1,32 @@ + + * @copyright 2015 Smiley + * @license MIT + */ + +namespace chillerlan\QRCodeTest; + +use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\Output\QRImage; +use chillerlan\QRCode\Output\QRImageOptions; +use chillerlan\QRCode\Output\QRString; +use chillerlan\QRCode\Output\QRStringOptions; + +class QRCodeTest extends \PHPUnit_Framework_TestCase{ + + public function testInstance(){ + $output = new QRString; + $options = new QROptions; + + $this->assertInstanceOf(QRString::class, $output); + $this->assertInstanceOf(QROptions::class, $options); + $this->assertInstanceOf(QRCode::class, new QRCode('data', $output, $options)); + } + +} diff --git a/tests/UtilTest.php b/tests/UtilTest.php index 0b94556fd..1a7276a34 100644 --- a/tests/UtilTest.php +++ b/tests/UtilTest.php @@ -7,9 +7,11 @@ * @license MIT */ +namespace chillerlan\QRCodeTest; + use chillerlan\QRCode\Util; -class UtilTest extends PHPUnit_Framework_TestCase{ +class UtilTest extends \PHPUnit_Framework_TestCase{ public function testIsNumber(){ $this->assertEquals(true, Util::isNumber('1234567890')); @@ -21,6 +23,7 @@ class UtilTest extends PHPUnit_Framework_TestCase{ $this->assertEquals(false, Util::isAlphaNum('#')); } + // http://stackoverflow.com/a/24755772 public function testIsKanji(){ $this->assertEquals(true, Util::isKanji('茗荷')); $this->assertEquals(false, Util::isKanji(''));