From a39c0dc3a301e0e2c9c8f8172f12f4746b0286b2 Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Fri, 28 Aug 2020 19:05:06 -0500 Subject: [PATCH] Support for full PHPUnit API --- .travis.yml | 1 + CHANGELOG.md | 5 + docs/supported_verifiers.md | 51 ++++- .../Verify/Verifiers/VerifyArrayTrait.php | 74 +++++-- .../Verify/Verifiers/VerifyDirectoryTrait.php | 81 ++++++++ .../Verify/Verifiers/VerifyFileTrait.php | 137 ++++++++++++- .../Verify/Verifiers/VerifyMixedTrait.php | 180 +++++++++++++----- .../Verify/Verifiers/VerifyStringTrait.php | 141 +++++++++++--- .../Verify/Verifiers/VerifyUnionTrait.php | 56 +++++- .../Verify/Verifiers/VerifyXmlTrait.php | 44 ++++- src/Codeception/Verify/Verify.php | 2 + 11 files changed, 680 insertions(+), 92 deletions(-) create mode 100644 src/Codeception/Verify/Verifiers/VerifyDirectoryTrait.php diff --git a/.travis.yml b/.travis.yml index b36bcaf..9b16d08 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ php: - 7.1 - 7.2 - 7.3 + - 7.4 cache: directories: diff --git a/CHANGELOG.md b/CHANGELOG.md index cc310e8..24e0e6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.5 + +* Support for full PHPUnit API `(42 new verifiers!)` +* Updated `supported_verifiers.md` documentation. + ## 1.4 * Improved code quality and maintainability. diff --git a/docs/supported_verifiers.md b/docs/supported_verifiers.md index 7acb8fa..bff0184 100644 --- a/docs/supported_verifiers.md +++ b/docs/supported_verifiers.md @@ -3,16 +3,29 @@ ### Array ``` contains +containsEquals containsOnly containsOnlyInstancesOf count hasKey hasNotKey notContains +notContainsEquals notContainsOnly notCount +notSameSize +sameSize ``` +### Directory +``` +directoryDoesNotExist +directoryExists +directoryIsNotReadable +directoryIsNotWritable +directoryIsReadable +directoryIsWritable +``` ### File ``` setIsFileExpectation @@ -22,6 +35,16 @@ exists notExists equalsJsonFile equalsXmlFile +fileEqualsCanonicalizing +fileEqualsIgnoringCase +fileIsNotReadable +fileIsNotWritable +fileIsReadable +fileIsWritable +fileNotEqualsCanonicalizing +fileNotEqualsIgnoringCase +jsonFileNotEqualsJsonFile +jsonStringNotEqualsJsonFile ``` ### Mixed @@ -31,19 +54,25 @@ equalsCanonicalizing equalsIgnoringCase equalsWithDelta false +finite greaterThan greaterOrEquals +infinite isInstanceOf array bool callable +isClosedResource float int +isIterable notArray notBool notCallable +isNotClosedResource notFloat notInt +isNotIterable notNumeric notObject notResource @@ -56,15 +85,19 @@ scalar string lessThan lessOrEquals +nan notEmpty notEqualsCanonicalizing notEqualsIgnoringCase notEqualsWithDelta +notFalse isNotInstanceOf notNull notSame +notTrue null same +that true ``` @@ -72,10 +105,17 @@ true ``` hasStaticAttribute notHasStaticAttribute +json +jsonStringNotEqualsJsonString +notRegExp equalsJsonString regExp stringContainsString stringContainsStringIgnoringCase +stringEqualsFileCanonicalizing +stringEqualsFileIgnoringCase +stringNotEqualsFileCanonicalizing +stringNotEqualsFileIgnoringCase notEndsWith endsWith equalsFile @@ -90,11 +130,17 @@ startsWith notEqualsFile ``` -### Object/String +### Union +##### Object/String ``` hasAttribute notHasAttribute ``` +##### File/Directory +``` +isNotReadable +isNotWritable +``` ### Throwable ``` @@ -105,4 +151,7 @@ doesNotThrow ### Xml ``` equalsXmlString +xmlFileNotEqualsXmlFile +xmlStringNotEqualsXmlFile +xmlStringNotEqualsXmlString ``` \ No newline at end of file diff --git a/src/Codeception/Verify/Verifiers/VerifyArrayTrait.php b/src/Codeception/Verify/Verifiers/VerifyArrayTrait.php index 8ce89e5..83d5d64 100644 --- a/src/Codeception/Verify/Verifiers/VerifyArrayTrait.php +++ b/src/Codeception/Verify/Verifiers/VerifyArrayTrait.php @@ -10,7 +10,7 @@ trait VerifyArrayTrait { /** - * Asserts that a haystack contains a needle. + * Verifies that a haystack contains a needle. * * @param $needle */ @@ -23,13 +23,22 @@ public function contains($needle) throw new InvalidVerifyException(__FUNCTION__, $this->actual); } + public function containsEquals($needle) + { + if(is_iterable($this->actual)) { + TestCase::assertContainsEquals($needle, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + /** - * Asserts that a haystack contains only values of a given type. + * Verifies that a haystack contains only values of a given type. * * @param string $type * @param bool|null $isNativeType */ - public function containsOnly($type, $isNativeType = null) + public function containsOnly(string $type, $isNativeType = null) { if(is_iterable($this->actual)) { TestCase::assertContainsOnly($type, $this->actual, $isNativeType, $this->message); @@ -39,11 +48,11 @@ public function containsOnly($type, $isNativeType = null) } /** - * Asserts that a haystack contains only instances of a given class name. + * Verifies that a haystack contains only instances of a given class name. * * @param string $className */ - public function containsOnlyInstancesOf($className) + public function containsOnlyInstancesOf(string $className) { if(is_iterable($this->actual)) { TestCase::assertContainsOnlyInstancesOf($className, $this->actual, $this->message); @@ -53,11 +62,11 @@ public function containsOnlyInstancesOf($className) } /** - * Asserts the number of elements of an array, Countable or Traversable. + * Verifies the number of elements of an array, Countable or Traversable. * * @param int $expectedCount */ - public function count($expectedCount) + public function count(int $expectedCount) { if(is_iterable($this->actual) || $this->actual instanceof Countable) { TestCase::assertCount($expectedCount, $this->actual, $this->message); @@ -67,7 +76,7 @@ public function count($expectedCount) } /** - * Asserts that an array has a specified key. + * Verifies that an array has a specified key. * * @param int|string $key */ @@ -81,7 +90,7 @@ public function hasKey($key) } /** - * Asserts that an array does not have a specified key. + * Verifies that an array does not have a specified key. * * @param int|string $key */ @@ -94,9 +103,8 @@ public function hasNotKey($key) throw new InvalidVerifyException(__FUNCTION__, $this->actual); } - /** - * Asserts that a haystack does not contain a needle. + * Verifies that a haystack does not contain a needle. * * @param $needle */ @@ -109,13 +117,22 @@ public function notContains($needle) throw new InvalidVerifyException(__FUNCTION__, $this->actual); } + public function notContainsEquals($needle) + { + if (is_iterable($this->actual)) { + TestCase::assertNotContainsEquals($needle, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + /** - * Asserts that a haystack does not contain only values of a given type. + * Verifies that a haystack does not contain only values of a given type. * * @param string $type * @param bool|null $isNativeType */ - public function notContainsOnly($type, $isNativeType = null) + public function notContainsOnly(string $type, $isNativeType = null) { if(is_iterable($this->actual)) { TestCase::assertNotContainsOnly($type, $this->actual, $isNativeType, $this->message); @@ -125,11 +142,11 @@ public function notContainsOnly($type, $isNativeType = null) } /** - * Asserts the number of elements of an array, Countable or Traversable. + * Verifies the number of elements of an array, Countable or Traversable. * * @param int $expectedCount */ - public function notCount($expectedCount) + public function notCount(int $expectedCount) { if(is_iterable($this->actual) || $this->actual instanceof Countable) { TestCase::assertNotCount($expectedCount, $this->actual, $this->message); @@ -138,4 +155,31 @@ public function notCount($expectedCount) throw new InvalidVerifyException(__FUNCTION__, $this->actual); } + /** + * Verifies that the size of two arrays (or `Countable` or `Traversable` objects) is not the same. + * + * @param Countable|iterable $expected + */ + public function notSameSize($expected) + { + if(is_iterable($this->actual) || $this->actual instanceof Countable) { + TestCase::assertNotSameSize($expected, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that the size of two arrays (or `Countable` or `Traversable` objects) is the same. + * + * @param Countable|iterable $expected + */ + public function sameSize($expected) + { + if(is_iterable($this->actual) || $this->actual instanceof Countable) { + TestCase::assertSameSize($expected, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } } \ No newline at end of file diff --git a/src/Codeception/Verify/Verifiers/VerifyDirectoryTrait.php b/src/Codeception/Verify/Verifiers/VerifyDirectoryTrait.php new file mode 100644 index 0000000..697bc0f --- /dev/null +++ b/src/Codeception/Verify/Verifiers/VerifyDirectoryTrait.php @@ -0,0 +1,81 @@ +actual)) { + TestCase::assertDirectoryDoesNotExist($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that a directory exists. + */ + public function directoryExists() + { + if(is_string($this->actual)) { + TestCase::assertDirectoryExists($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that a directory exists and is not readable. + */ + public function directoryIsNotReadable() + { + if(is_string($this->actual)) { + TestCase::assertDirectoryIsNotReadable($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that a directory exists and is not writable. + */ + public function directoryIsNotWritable() + { + if(is_string($this->actual)) { + TestCase::assertDirectoryIsNotWritable($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that a directory exists and is readable. + */ + public function directoryIsReadable() + { + if(is_string($this->actual)) { + TestCase::assertDirectoryIsReadable($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that a directory exists and is writable. + */ + public function directoryIsWritable() + { + if(is_string($this->actual)) { + TestCase::assertDirectoryIsWritable($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } +} \ No newline at end of file diff --git a/src/Codeception/Verify/Verifiers/VerifyFileTrait.php b/src/Codeception/Verify/Verifiers/VerifyFileTrait.php index 9836153..ec9f710 100644 --- a/src/Codeception/Verify/Verifiers/VerifyFileTrait.php +++ b/src/Codeception/Verify/Verifiers/VerifyFileTrait.php @@ -2,6 +2,7 @@ namespace Codeception\Verify\Verifiers; +use Codeception\Exception\InvalidVerifyException; use Codeception\PHPUnit\TestCase; use Exception; @@ -10,7 +11,7 @@ trait VerifyFileTrait /** * @param boolean $isFileExpectation */ - public function setIsFileExpectation($isFileExpectation) + public function setIsFileExpectation(bool $isFileExpectation) { $this->isFileExpectation = $isFileExpectation; } @@ -22,6 +23,7 @@ public function equals($expected, $delta = 0) } else { TestCase::assertFileEquals($expected, $this->actual, $this->message); } + // TestCase::assertEquals($expected, $actual, $message); } public function notEquals($expected, $delta = 0) @@ -31,6 +33,7 @@ public function notEquals($expected, $delta = 0) } else { TestCase::assertFileNotEquals($expected, $this->actual, $this->message); } + // TestCase::assertNotEquals($expected, $actual, $message); } public function exists() @@ -66,4 +69,136 @@ public function equalsXmlFile($file) TestCase::assertXmlFileEqualsXmlFile($file, $this->actual, $this->message); } } + + /** + * Verifies that the contents of one file is equal to the contents of another file (canonicalizing). + * + * @param $expected + */ + public function fileEqualsCanonicalizing($expected) + { + if (is_string($this->actual)) { + TestCase::assertFileEqualsCanonicalizing($expected, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that the contents of one file is equal to the contents of another file (ignoring case). + * + * @param $expected + */ + public function fileEqualsIgnoringCase($expected) + { + if (is_string($this->actual)) { + TestCase::assertFileEqualsIgnoringCase($expected, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that a file exists and is not readable. + */ + public function fileIsNotReadable() + { + if (is_string($this->actual)) { + TestCase::assertFileIsNotReadable($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that a file exists and is not writable. + */ + public function fileIsNotWritable() + { + if (is_string($this->actual)) { + TestCase::assertFileIsNotWritable($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that a file exists and is readable. + */ + public function fileIsReadable() + { + if (is_string($this->actual)) { + TestCase::assertFileIsReadable($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that a file exists and is writable. + */ + public function fileIsWritable() + { + if (is_string($this->actual)) { + TestCase::assertFileIsWritable($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that the contents of one file is not equal to the contents of another file (canonicalizing). + * + * @param $expected + */ + public function fileNotEqualsCanonicalizing($expected) + { + if (is_string($this->actual)) { + TestCase::assertFileNotEqualsCanonicalizing($expected, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that the contents of one file is not equal to the contents of another file (ignoring case). + * + * @param $expected + */ + public function fileNotEqualsIgnoringCase($expected) + { + if (is_string($this->actual)) { + TestCase::assertFileNotEqualsIgnoringCase($expected, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that two JSON files are not equal. + * + * @param string $expectedFile + */ + public function jsonFileNotEqualsJsonFile(string $expectedFile) + { + if (is_string($this->actual)) { + TestCase::assertJsonFileNotEqualsJsonFile($expectedFile, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that the generated JSON encoded object and the content of the given file are not equal. + * + * @param string $expectedFile + */ + public function jsonStringNotEqualsJsonFile(string $expectedFile) + { + if (is_string($this->actual)) { + TestCase::assertJsonStringNotEqualsJsonFile($expectedFile, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } } \ No newline at end of file diff --git a/src/Codeception/Verify/Verifiers/VerifyMixedTrait.php b/src/Codeception/Verify/Verifiers/VerifyMixedTrait.php index 966a0b9..f07e503 100644 --- a/src/Codeception/Verify/Verifiers/VerifyMixedTrait.php +++ b/src/Codeception/Verify/Verifiers/VerifyMixedTrait.php @@ -2,12 +2,14 @@ namespace Codeception\Verify\Verifiers; +use Codeception\Exception\InvalidVerifyException; use Codeception\PHPUnit\TestCase; +use PHPUnit\Framework\Constraint\Constraint; trait VerifyMixedTrait { /** - * Asserts that a variable is empty. + * Verifies that a variable is empty. */ public function isEmpty() { @@ -15,7 +17,7 @@ public function isEmpty() } /** - * Asserts that two variables are equal (canonicalizing). + * Verifies that two variables are equal (canonicalizing). * * @param $expected */ @@ -25,7 +27,7 @@ public function equalsCanonicalizing($expected) } /** - * Asserts that two variables are equal (ignoring case). + * Verifies that two variables are equal (ignoring case). * * @param $expected */ @@ -35,18 +37,18 @@ public function equalsIgnoringCase($expected) } /** - * Asserts that two variables are equal (with delta). + * Verifies that two variables are equal (with delta). * * @param $expected * @param float $delta */ - public function equalsWithDelta($expected, $delta) + public function equalsWithDelta($expected, float $delta) { TestCase::assertEqualsWithDelta($expected, $this->actual, $delta, $this->message); } /** - * Asserts that a condition is false. + * Verifies that a condition is false. */ public function false() { @@ -54,7 +56,15 @@ public function false() } /** - * Asserts that a value is greater than another value. + * Verifies that a variable is finite. + */ + public function finite() + { + TestCase::assertFinite($this->actual, $this->message); + } + + /** + * Verifies that a value is greater than another value. * * @param $expected */ @@ -64,7 +74,7 @@ public function greaterThan($expected) } /** - * Asserts that a value is greater than or equal to another value. + * Verifies that a value is greater than or equal to another value. * * @param $expected */ @@ -74,17 +84,25 @@ public function greaterOrEquals($expected) } /** - * Asserts that a variable is of a given type. + * Verifies that a variable is infinite. + */ + public function infinite() + { + TestCase::assertInfinite($this->actual, $this->message); + } + + /** + * Verifies that a variable is of a given type. * * @param string $expected */ - public function isInstanceOf($expected) + public function isInstanceOf(string $expected) { TestCase::assertInstanceOf($expected, $this->actual, $this->message); } /** - * Asserts that a variable is of type array. + * Verifies that a variable is of type array. */ public function array() { @@ -92,7 +110,7 @@ public function array() } /** - * Asserts that a variable is of type bool. + * Verifies that a variable is of type bool. */ public function bool() { @@ -100,7 +118,7 @@ public function bool() } /** - * Asserts that a variable is of type callable. + * Verifies that a variable is of type callable. */ public function callable() { @@ -108,7 +126,15 @@ public function callable() } /** - * Asserts that a variable is of type float. + * Verifies that a variable is of type resource and is closed. + */ + public function isClosedResource() + { + TestCase::assertIsClosedResource($this->actual, $this->message); + } + + /** + * Verifies that a variable is of type float. */ public function float() { @@ -116,7 +142,7 @@ public function float() } /** - * Asserts that a variable is of type int. + * Verifies that a variable is of type int. */ public function int() { @@ -124,7 +150,15 @@ public function int() } /** - * Asserts that a variable is not of type array. + * Verifies that a variable is of type iterable. + */ + public function isIterable() + { + TestCase::assertIsIterable($this->actual, $this->message); + } + + /** + * Verifies that a variable is not of type array. */ public function notArray() { @@ -132,7 +166,7 @@ public function notArray() } /** - * Asserts that a variable is not of type bool. + * Verifies that a variable is not of type bool. */ public function notBool() { @@ -140,7 +174,7 @@ public function notBool() } /** - * Asserts that a variable is not of type callable. + * Verifies that a variable is not of type callable. */ public function notCallable() { @@ -148,7 +182,15 @@ public function notCallable() } /** - * Asserts that a variable is not of type float. + * Verifies that a variable is not of type resource. + */ + public function isNotClosedResource() + { + TestCase::assertIsNotClosedResource($this->actual, $this->message); + } + + /** + * Verifies that a variable is not of type float. */ public function notFloat() { @@ -156,7 +198,7 @@ public function notFloat() } /** - * Asserts that a variable is not of type int. + * Verifies that a variable is not of type int. */ public function notInt() { @@ -164,7 +206,15 @@ public function notInt() } /** - * Asserts that a variable is not of type numeric. + * Verifies that a variable is not of type iterable. + */ + public function isNotIterable() + { + TestCase::assertIsNotIterable($this->actual, $this->message); + } + + /** + * Verifies that a variable is not of type numeric. */ public function notNumeric() { @@ -172,7 +222,7 @@ public function notNumeric() } /** - * Asserts that a variable is not of type object. + * Verifies that a variable is not of type object. */ public function notObject() { @@ -180,7 +230,7 @@ public function notObject() } /** - * Asserts that a variable is not of type resource. + * Verifies that a variable is not of type resource. */ public function notResource() { @@ -188,7 +238,7 @@ public function notResource() } /** - * Asserts that a variable is not of type scalar. + * Verifies that a variable is not of type scalar. */ public function notScalar() { @@ -196,7 +246,7 @@ public function notScalar() } /** - * Asserts that a variable is not of type string. + * Verifies that a variable is not of type string. */ public function notString() { @@ -204,7 +254,7 @@ public function notString() } /** - * Asserts that a variable is of type numeric. + * Verifies that a variable is of type numeric. */ public function numeric() { @@ -212,7 +262,7 @@ public function numeric() } /** - * Asserts that a variable is of type object. + * Verifies that a variable is of type object. */ public function object() { @@ -220,7 +270,7 @@ public function object() } /** - * Asserts that a variable is of type resource. + * Verifies that a variable is of type resource. */ public function resource() { @@ -228,7 +278,7 @@ public function resource() } /** - * Asserts that a variable is of type scalar. + * Verifies that a variable is of type scalar. */ public function scalar() { @@ -236,7 +286,7 @@ public function scalar() } /** - * Asserts that a variable is of type string. + * Verifies that a variable is of type string. */ public function string() { @@ -244,7 +294,7 @@ public function string() } /** - * Asserts that a value is smaller than another value. + * Verifies that a value is smaller than another value. * * @param $expected */ @@ -254,7 +304,7 @@ public function lessThan($expected) } /** - * Asserts that a value is smaller than or equal to another value. + * Verifies that a value is smaller than or equal to another value. * * @param $expected */ @@ -264,7 +314,15 @@ public function lessOrEquals($expected) } /** - * Asserts that a variable is not empty. + * Verifies that a variable is nan. + */ + public function nan() + { + TestCase::assertNan($this->actual, $this->message); + } + + /** + * Verifies that a variable is not empty. */ public function notEmpty() { @@ -272,7 +330,7 @@ public function notEmpty() } /** - * Asserts that two variables are not equal (canonicalizing). + * Verifies that two variables are not equal (canonicalizing). * * @param $expected */ @@ -282,7 +340,7 @@ public function notEqualsCanonicalizing($expected) } /** - * Asserts that two variables are not equal (ignoring case). + * Verifies that two variables are not equal (ignoring case). * * @param $expected */ @@ -292,28 +350,38 @@ public function notEqualsIgnoringCase($expected) } /** - * Asserts that two variables are not equal (with delta). + * Verifies that two variables are not equal (with delta). * * @param $expected * @param float $delta */ - public function notEqualsWithDelta($expected, $delta) + public function notEqualsWithDelta($expected, float $delta) { TestCase::assertNotEqualsWithDelta($expected, $this->actual, $delta, $this->message); } /** - * Asserts that a variable is not of a given type. + * Verifies that a condition is not false. + * + * @param $condition + */ + public function notFalse($condition) + { + TestCase::assertNotFalse($condition, $this->message); + } + + /** + * Verifies that a variable is not of a given type. * * @param string $expected */ - public function isNotInstanceOf($expected) + public function isNotInstanceOf(string $expected) { TestCase::assertNotInstanceOf($expected, $this->actual, $this->message); } /** - * Asserts that a variable is not null. + * Verifies that a variable is not null. */ public function notNull() { @@ -321,7 +389,7 @@ public function notNull() } /** - * Asserts that two variables do not have the same type and value. + * Verifies that two variables do not have the same type and value. * * @param $expected */ @@ -331,7 +399,17 @@ public function notSame($expected) } /** - * Asserts that a variable is null. + * Verifies that a condition is not true. + * + * @param $condition + */ + public function notTrue($condition) + { + TestCase::assertNotTrue($condition, $this->message); + } + + /** + * Verifies that a variable is null. */ public function null() { @@ -339,7 +417,7 @@ public function null() } /** - * Asserts that two variables have the same type and value. + * Verifies that two variables have the same type and value. * * @param $expected */ @@ -349,7 +427,21 @@ public function same($expected) } /** - * Asserts that a condition is true. + * Evaluates a PHPUnit\Framework\Constraint matcher object. + * + * @param $value + */ + public function that($value) + { + if ($this->actual instanceof Constraint) { + TestCase::assertThat($value, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that a condition is true. */ public function true() { diff --git a/src/Codeception/Verify/Verifiers/VerifyStringTrait.php b/src/Codeception/Verify/Verifiers/VerifyStringTrait.php index 53fd96f..c0705ac 100644 --- a/src/Codeception/Verify/Verifiers/VerifyStringTrait.php +++ b/src/Codeception/Verify/Verifiers/VerifyStringTrait.php @@ -8,11 +8,11 @@ trait VerifyStringTrait { /** - * Asserts that a class has a specified static attribute. + * Verifies that a class has a specified static attribute. * * @param string $attributeName */ - public function hasStaticAttribute($attributeName) + public function hasStaticAttribute(string $attributeName) { if (is_string($this->actual)) { TestCase::assertClassHasStaticAttribute($attributeName, $this->actual, $this->message); @@ -22,11 +22,11 @@ public function hasStaticAttribute($attributeName) } /** - * Asserts that a class does not have a specified static attribute. + * Verifies that a class does not have a specified static attribute. * * @param string $attributeName */ - public function notHasStaticAttribute($attributeName) + public function notHasStaticAttribute(string $attributeName) { if (is_string($this->actual)) { TestCase::assertClassNotHasStaticAttribute($attributeName, $this->actual, $this->message); @@ -35,9 +35,44 @@ public function notHasStaticAttribute($attributeName) throw new InvalidVerifyException(__FUNCTION__, $this->actual); } + /** + * Verifies that a string is a valid JSON string. + */ + public function json() + { + if (is_string($this->actual)) { + TestCase::assertJson($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that two given JSON encoded objects or arrays are not equal. + * + * @param string $expectedJson + */ + public function jsonStringNotEqualsJsonString(string $expectedJson) + { + TestCase::assertJsonStringNotEqualsJsonString($expectedJson, $this->actual, $this->message); + } + + /** + * Verifies that a string does not match a given regular expression. + * + * @param string $pattern + */ + public function notRegExp(string $pattern) + { + if (is_string($this->actual)) { + TestCase::assertNotRegExp($pattern, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } /** - * Asserts that two given JSON encoded objects or arrays are equal. + * Verifies that two given JSON encoded objects or arrays are equal. * * @param $string */ @@ -51,11 +86,11 @@ public function equalsJsonString($string) } /** - * Asserts that a string matches a given regular expression. + * Verifies that a string matches a given regular expression. * * @param string $pattern */ - public function regExp($pattern) + public function regExp(string $pattern) { if (is_string($this->actual)) { TestCase::assertRegExp($pattern, $this->actual, $this->message); @@ -68,7 +103,7 @@ public function regExp($pattern) /** * @param string $needle */ - public function stringContainsString($needle) + public function stringContainsString(string $needle) { if (is_string($this->actual)) { TestCase::assertStringContainsString($needle, $this->actual, $this->message); @@ -87,11 +122,39 @@ public function stringContainsStringIgnoringCase($needle) } /** - * Asserts that a string ends not with a given suffix. + * Verifies that the contents of a string is equal to the contents of a file (canonicalizing). + * + * @param string $expectedFile + */ + public function stringEqualsFileCanonicalizing(string $expectedFile) + { + if (is_string($this->actual)) { + TestCase::assertStringEqualsFileCanonicalizing($expectedFile, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that the contents of a string is equal to the contents of a file (ignoring case). + * + * @param string $expectedFile + */ + public function stringEqualsFileIgnoringCase(string $expectedFile) + { + if (is_string($this->actual)) { + TestCase::assertStringEqualsFileIgnoringCase($expectedFile, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that a string ends not with a given suffix. * * @param string $suffix */ - public function notEndsWith($suffix) + public function notEndsWith(string $suffix) { if(is_string($this->actual)) { TestCase::assertStringEndsNotWith($suffix, $this->actual, $this->message); @@ -101,11 +164,11 @@ public function notEndsWith($suffix) } /** - * Asserts that a string ends with a given suffix. + * Verifies that a string ends with a given suffix. * * @param string $suffix */ - public function endsWith($suffix) + public function endsWith(string $suffix) { if(is_string($this->actual)) { TestCase::assertStringEndsWith($suffix, $this->actual, $this->message); @@ -115,7 +178,7 @@ public function endsWith($suffix) } /** - * Asserts that the contents of a string is equal to the contents of a file. + * Verifies that the contents of a string is equal to the contents of a file. * * @param string $expectedFile */ @@ -129,11 +192,11 @@ public function equalsFile(string $expectedFile) } /** - * Asserts that a string matches a given format string. + * Verifies that a string matches a given format string. * * @param string $format */ - public function matchesFormat($format) + public function matchesFormat(string $format) { if(is_string($this->actual)) { TestCase::assertStringMatchesFormat($format, $this->actual, $this->message); @@ -143,11 +206,11 @@ public function matchesFormat($format) } /** - * Asserts that a string matches a given format file. + * Verifies that a string matches a given format file. * * @param string $formatFile */ - public function matchesFormatFile($formatFile) + public function matchesFormatFile(string $formatFile) { if(is_string($this->actual)) { TestCase::assertStringMatchesFormatFile($formatFile, $this->actual, $this->message); @@ -159,7 +222,7 @@ public function matchesFormatFile($formatFile) /** * @param string $needle */ - public function stringNotContainsString($needle) + public function stringNotContainsString(string $needle) { if(is_string($this->actual)) { TestCase::assertStringNotContainsString($needle, $this->actual, $this->message); @@ -171,7 +234,7 @@ public function stringNotContainsString($needle) /** * @param string $needle */ - public function stringNotContainsStringIgnoringCase($needle) + public function stringNotContainsStringIgnoringCase(string $needle) { if(is_string($this->actual)) { TestCase::assertStringNotContainsStringIgnoringCase($needle, $this->actual, $this->message); @@ -180,7 +243,33 @@ public function stringNotContainsStringIgnoringCase($needle) throw new InvalidVerifyException(__FUNCTION__, $this->actual); } + /** + * Verifies that the contents of a string is not equal to the contents of a file (canonicalizing). + * + * @param string $expectedFile + */ + public function stringNotEqualsFileCanonicalizing(string $expectedFile) + { + if(is_string($this->actual)) { + TestCase::assertStringNotEqualsFileCanonicalizing($expectedFile, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + /** + * Verifies that the contents of a string is not equal to the contents of a file (ignoring case). + * + * @param string $expectedFile + */ + public function stringNotEqualsFileIgnoringCase(string $expectedFile) + { + if(is_string($this->actual)) { + TestCase::assertStringNotEqualsFileIgnoringCase($expectedFile, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } public function notMatchesFormat($format) { @@ -192,11 +281,11 @@ public function notMatchesFormat($format) } /** - * Asserts that a string does not match a given format string. + * Verifies that a string does not match a given format string. * * @param string $formatFile */ - public function notMatchesFormatFile($formatFile) + public function notMatchesFormatFile(string $formatFile) { if(is_string($this->actual)) { TestCase::assertStringNotMatchesFormatFile($formatFile, $this->actual, $this->message); @@ -206,11 +295,11 @@ public function notMatchesFormatFile($formatFile) } /** - * Asserts that a string starts not with a given prefix. + * Verifies that a string starts not with a given prefix. * * @param string $prefix */ - public function notStartsWith($prefix) + public function notStartsWith(string $prefix) { if(is_string($this->actual)) { TestCase::assertStringStartsNotWith($prefix, $this->actual, $this->message); @@ -220,11 +309,11 @@ public function notStartsWith($prefix) } /** - * Asserts that a string starts with a given prefix. + * Verifies that a string starts with a given prefix. * * @param string $prefix */ - public function startsWith($prefix) + public function startsWith(string $prefix) { if(is_string($this->actual)) { TestCase::assertStringStartsWith($prefix, $this->actual, $this->message); @@ -234,7 +323,7 @@ public function startsWith($prefix) } /** - * Asserts that the contents of a string is not equal to the contents of a file. + * Verifies that the contents of a string is not equal to the contents of a file. * * @param string $expectedFile */ diff --git a/src/Codeception/Verify/Verifiers/VerifyUnionTrait.php b/src/Codeception/Verify/Verifiers/VerifyUnionTrait.php index fa441af..484d996 100644 --- a/src/Codeception/Verify/Verifiers/VerifyUnionTrait.php +++ b/src/Codeception/Verify/Verifiers/VerifyUnionTrait.php @@ -8,11 +8,11 @@ trait VerifyUnionTrait { /** - * Asserts that a class has a specified attribute. + * Verifies that a class has a specified attribute. * * @param string $attributeName */ - public function hasAttribute($attributeName) + public function hasAttribute(string $attributeName) { if (is_object($this->actual)) { TestCase::assertObjectHasAttribute($attributeName, $this->actual, $this->message); @@ -25,11 +25,11 @@ public function hasAttribute($attributeName) } /** - * Asserts that a class does not have a specified attribute. + * Verifies that a class does not have a specified attribute. * * @param string $attributeName */ - public function notHasAttribute($attributeName) + public function notHasAttribute(string $attributeName) { if (is_string($this->actual)) { TestCase::assertClassNotHasAttribute($attributeName, $this->actual, $this->message); @@ -40,4 +40,52 @@ public function notHasAttribute($attributeName) } throw new InvalidVerifyException(__FUNCTION__, $this->actual); } + + /** + * Verifies that a file/dir exists and is not readable. + */ + public function isNotReadable() + { + if (is_string($this->actual)) { + TestCase::assertIsNotReadable($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that a file/dir exists and is not writable. + */ + public function isNotWritable() + { + if (is_string($this->actual)) { + TestCase::assertIsNotWritable($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that a file/dir is readable. + */ + public function isReadable() + { + if (is_string($this->actual)) { + TestCase::assertIsReadable($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Asserts that a file/dir exists and is writable. + */ + public function isWritable() + { + if (is_string($this->actual)) { + TestCase::assertIsWritable($this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } } \ No newline at end of file diff --git a/src/Codeception/Verify/Verifiers/VerifyXmlTrait.php b/src/Codeception/Verify/Verifiers/VerifyXmlTrait.php index 7564bb0..f95c2c9 100644 --- a/src/Codeception/Verify/Verifiers/VerifyXmlTrait.php +++ b/src/Codeception/Verify/Verifiers/VerifyXmlTrait.php @@ -9,7 +9,7 @@ trait VerifyXmlTrait { /** - * Asserts that two XML documents are equal. + * Verifies that two XML documents are equal. * * @param DOMDocument|string $expectedXml */ @@ -21,4 +21,46 @@ public function equalsXmlString($expectedXml) } throw new InvalidVerifyException(__FUNCTION__, $this->actual); } + + /** + * Verifies that two XML files are not equal. + * + * @param string $expectedFile + */ + public function xmlFileNotEqualsXmlFile(string $expectedFile) + { + if (is_file($this->actual)) { + TestCase::assertXmlFileNotEqualsXmlFile($expectedFile, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that two XML documents are not equal. + * + * @param string $expectedFile + */ + public function xmlStringNotEqualsXmlFile(string $expectedFile) + { + if (is_string($this->actual) || $this->actual instanceof DOMDocument) { + TestCase::assertXmlStringNotEqualsXmlFile($expectedFile, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } + + /** + * Verifies that two XML documents are not equal. + * + * @param DOMDocument|string $expectedXml + */ + public function xmlStringNotEqualsXmlString($expectedXml) + { + if (is_string($this->actual) || $this->actual instanceof DOMDocument) { + TestCase::assertXmlStringNotEqualsXmlString($expectedXml, $this->actual, $this->message); + return; + } + throw new InvalidVerifyException(__FUNCTION__, $this->actual); + } } \ No newline at end of file diff --git a/src/Codeception/Verify/Verify.php b/src/Codeception/Verify/Verify.php index 1a2c764..726c545 100644 --- a/src/Codeception/Verify/Verify.php +++ b/src/Codeception/Verify/Verify.php @@ -3,6 +3,7 @@ namespace Codeception\Verify; use Codeception\Verify\Verifiers\VerifyArrayTrait; +use Codeception\Verify\Verifiers\VerifyDirectoryTrait; use Codeception\Verify\Verifiers\VerifyFileTrait; use Codeception\Verify\Verifiers\VerifyMixedTrait; use Codeception\Verify\Verifiers\VerifyStringTrait; @@ -14,6 +15,7 @@ class Verify { use VerifyArrayTrait, + VerifyDirectoryTrait, VerifyFileTrait, VerifyMixedTrait, VerifyStringTrait,