From cdd905f4156af483844bed9eda0373ebffe58e8a Mon Sep 17 00:00:00 2001 From: smiley Date: Tue, 9 Feb 2016 02:02:08 +0100 Subject: [PATCH] more QRCode tests --- tests/QRCodeTest.php | 61 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/tests/QRCodeTest.php b/tests/QRCodeTest.php index a509fa3a2..0bfebc04f 100644 --- a/tests/QRCodeTest.php +++ b/tests/QRCodeTest.php @@ -20,13 +20,62 @@ use chillerlan\QRCode\Output\QRStringOptions; class QRCodeTest extends \PHPUnit_Framework_TestCase{ - public function testInstance(){ - $output = new QRString; - $options = new QROptions; + /** + * @var \chillerlan\QRCode\QROptions + */ + protected $options; - $this->assertInstanceOf(QRString::class, $output); - $this->assertInstanceOf(QROptions::class, $options); - $this->assertInstanceOf(QRCode::class, new QRCode('data', $output, $options)); + /** + * @var \chillerlan\QRCode\Output\QROutputInterface + */ + protected $output; + + protected function setUp(){ + $this->options = new QROptions; + $this->output = new QRString; + } + + public function testInstance(){ + $this->assertInstanceOf(QRString::class, $this->output); + $this->assertInstanceOf(QROptions::class, $this->options); + $this->assertInstanceOf(QRCode::class, new QRCode('foobar', $this->output, $this->options)); + } + + public function stringDataProvider(){ + return [ + ['1234567890'], + ['ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'], + ['#\\'], + ['茗荷'], + ]; + } + + /** + * @dataProvider stringDataProvider + */ + public function testDataCoverage($data){ + (new QRCode($data, new QRString))->getRawData(); + } + + public function testTypeAutoOverride(){ + $this->options->typeNumber = QRCode::TYPE_05; + new QRCode('foobar', new QRString, $this->options); + } + /** + * @expectedException \chillerlan\QRCode\QRCodeException + * @expectedExceptionMessage No data given. + */ + public function testNoDataException(){ + new QRCode('', new QRString); + } + + /** + * @expectedException \chillerlan\QRCode\QRCodeException + * @expectedExceptionMessage Invalid error correct level: 42 + */ + public function testErrorCorrectLevelException(){ + $this->options->errorCorrectLevel = 42; + new QRCode('foobar', new QRString, $this->options); } }