From ee6ca6044d68565dfd019282d89ab72bf6e3fc36 Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Sat, 13 Jul 2019 22:50:46 +0300 Subject: [PATCH] Added new assertions --- README.md | 27 ++++++++ composer.json | 6 +- src/Codeception/Verify.php | 122 ++++++++++++++++++++++++++++++++++++- tests/VerifyTest.php | 72 ++++++++++++++++++++++ 4 files changed, 222 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d3ea4d9..b918559 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,32 @@ verify($user->getPosts())->notNull(); // empty verify($user->getComments())->isEmpty(); verify($user->getRoles())->notEmpty(); + +//Other methods: +* stringContainsString +* stringNotContainsString +* stringContainsStringIgnoringCase +* stringNotContainsStringIgnoringCase +* array +* bool +* float +* int +* numeric +* object +* resource +* string +* scalar +* callable +* notArray +* notBool +* notFloat +* notInt +* notNumeric +* notObject +* notResource +* notString +* notScalar +* notCallable ``` Shorthands for testing truth/fallacy: @@ -51,6 +77,7 @@ verify_that($user->isActivated()); verify_not($user->isBanned()); ``` + These two functions don't check for strict true/false matching, rather `empty` function is used. `verify_that` checks that result is not empty value, `verify_not` does the opposite. diff --git a/composer.json b/composer.json index 9a271a3..231b9ff 100644 --- a/composer.json +++ b/composer.json @@ -10,10 +10,8 @@ ], "require": { "php": ">= 7.0", - "phpunit/phpunit": "> 6.0" - }, - "require-dev": { - "codeception/phpunit-wrapper": ">6.0.15 <6.1.0 | ^6.6.1 | ^7.7.1 | ^8.0.4" + "phpunit/phpunit": "> 6.0", + "codeception/phpunit-wrapper": ">6.0.15 <6.1.0 | ^6.6.1 | ^7.7.1 | ^8.0.4" }, "autoload": { "files": ["src/Codeception/function.php"], diff --git a/src/Codeception/Verify.php b/src/Codeception/Verify.php index 5b4796f..a6d8a96 100644 --- a/src/Codeception/Verify.php +++ b/src/Codeception/Verify.php @@ -1,7 +1,7 @@ actual, $this->description); } + + public function stringContainsString($needle) + { + a::assertStringContainsString($needle, $this->actual, $this->description); + } + + public function stringNotContainsString($needle) + { + a::assertStringNotContainsString($needle, $this->actual, $this->description); + } + + public function stringContainsStringIgnoringCase($needle) + { + a::assertStringContainsStringIgnoringCase($needle, $this->actual, $this->description); + } + + public function stringNotContainsStringIgnoringCase($needle) + { + a::assertStringNotContainsStringIgnoringCase($needle, $this->actual, $this->description); + } + + public function array() + { + a::assertIsArray($this->actual, $this->description); + } + + public function bool() + { + a::assertIsBool($this->actual, $this->description); + } + + public function float() + { + a::assertIsFloat($this->actual, $this->description); + } + + public function int() + { + a::assertIsInt($this->actual, $this->description); + } + + public function numeric() + { + a::assertIsNumeric($this->actual, $this->description); + } + + public function object() + { + a::assertIsObject($this->actual, $this->description); + } + + public function resource() + { + a::assertIsResource($this->actual, $this->description); + } + + public function string() + { + a::assertIsString($this->actual, $this->description); + } + + public function scalar() + { + a::assertIsScalar($this->actual, $this->description); + } + + public function callable() + { + a::assertIsCallable($this->actual, $this->description); + } + + public function notArray() + { + a::assertIsNotArray($this->actual, $this->description); + } + + public function notBool() + { + a::assertIsNotBool($this->actual, $this->description); + } + + public function notFloat() + { + a::assertIsNotFloat($this->actual, $this->description); + } + + public function notInt() + { + a::assertIsNotInt($this->actual, $this->description); + } + + public function notNumeric() + { + a::assertIsNotNumeric($this->actual, $this->description); + } + + public function notObject() + { + a::assertIsNotObject($this->actual, $this->description); + } + + public function notResource() + { + a::assertIsNotResource($this->actual, $this->description); + } + + public function notString() + { + a::assertIsNotString($this->actual, $this->description); + } + + public function notScalar() + { + a::assertIsNotScalar($this->actual, $this->description); + } + + public function notCallable() + { + a::assertIsNotCallable($this->actual, $this->description); + } } diff --git a/tests/VerifyTest.php b/tests/VerifyTest.php index 55ae7a9..24f3aaf 100644 --- a/tests/VerifyTest.php +++ b/tests/VerifyTest.php @@ -218,6 +218,78 @@ public function testEqualsXmlString() expect('BazBaz') ->equalsXmlString('BazBaz'); } + + public function testStringContainsString() + { + verify('foo bar')->stringContainsString('o b'); + verify('foo bar')->stringNotContainsString('BAR'); + } + + public function testStringContainsStringIgnoringCase() + { + verify('foo bar')->stringContainsStringIgnoringCase('O b'); + verify('foo bar')->stringNotContainsStringIgnoringCase('baz'); + } + + public function testIsString() + { + verify('foo bar')->string(); + verify(false)->notString(); + } + + public function testIsArray() + { + verify([1,2,3])->array(); + verify(false)->notArray(); + } + + public function testIsBool() + { + verify(false)->bool(); + verify([1,2,3])->notBool(); + } + + public function testIsFloat() + { + verify(1.5)->float(); + verify(1)->notFloat(); + } + + public function testIsInt() + { + verify(5)->int(); + verify(1.5)->notInt(); + } + + public function testIsNumeric() + { + verify('1.5')->numeric(); + verify('foo bar')->notNumeric(); + } + + public function testIsObject() + { + verify(new stdClass)->object(); + verify(false)->notObject(); + } + + public function testIsResource() + { + verify(fopen(__FILE__, 'r'))->resource(); + verify(false)->notResource(); + } + + public function testIsScalar() + { + verify('foo bar')->scalar(); + verify([1,2,3])->notScalar(); + } + + public function testIsCallable() + { + verify(function() {})->callable(); + verify(false)->notCallable(); + } }