From 1db0f3cfe2614ac33023a7eaaceec9c735127b56 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 13 Feb 2024 17:36:12 -0600 Subject: [PATCH] [#ests] - annotations tests for phpunit --- .../Adapter/StreamEmptyDataFixture.php | 43 +++ .../Adapter/StreamFileExistsFixture.php | 31 ++ .../Annotations/Adapter/StreamFixture.php | 38 +++ .../Adapter/StreamWrongDataFixture.php | 43 +++ .../data/fixtures/Annotations/TestClass.php | 125 +++++++ .../data/fixtures/Annotations/TestClassNs.php | 33 ++ .../data/fixtures/Annotations/TestInvalid.php | 19 ++ .../fixtures/Traits/AnnotationsTrait2.php | 47 +++ tests/unit/Acl/Adapter/Memory/AddRoleTest.php | 2 +- .../unit/Acl/Adapter/Memory/IsAllowedTest.php | 1 - .../{ConstructCest.php => ConstructTest.php} | 105 +++--- .../Annotations/Adapter/GetConstantsTest.php | 96 ++++++ .../Annotations/Adapter/GetMethodCest.php | 57 ---- .../Annotations/Adapter/GetMethodsCest.php | 71 ---- .../Annotations/Adapter/GetMethodsTest.php | 115 +++++++ ...opertiesCest.php => GetPropertiesTest.php} | 40 +-- ...etPropertyCest.php => GetPropertyTest.php} | 38 ++- ...SetReaderCest.php => GetSetReaderTest.php} | 36 +- .../Adapter/{GetCest.php => GetTest.php} | 36 +- .../Annotations/Adapter/ReadWriteCest.php | 63 ---- .../Annotations/Adapter/ReadWriteTest.php | 129 ++++++++ .../{ConstructCest.php => ConstructTest.php} | 10 +- ...etArgumentCest.php => GetArgumentTest.php} | 13 +- ...ArgumentsCest.php => GetArgumentsTest.php} | 10 +- ...mentsCest.php => GetExprArgumentsTest.php} | 10 +- .../Annotation/GetExpressionCest.php | 63 ---- .../Annotation/GetExpressionTest.php | 107 ++++++ .../{GetNameCest.php => GetNameTest.php} | 10 +- ...umentCest.php => GetNamedArgumentTest.php} | 12 +- ...eterCest.php => GetNamedParameterTest.php} | 12 +- ...asArgumentCest.php => HasArgumentTest.php} | 16 +- ...umentsCest.php => NumberArgumentsTest.php} | 10 +- .../{LoadCest.php => LoadTest.php} | 41 +-- ...ewInstanceCest.php => NewInstanceTest.php} | 66 ++-- .../{ConstructCest.php => ConstructTest.php} | 16 +- .../{CountCest.php => CountTest.php} | 10 +- .../{CurrentCest.php => CurrentTest.php} | 16 +- .../{GetAllCest.php => GetAllTest.php} | 12 +- ...tationsCest.php => GetAnnotationsTest.php} | 10 +- .../Collection/{GetCest.php => GetTest.php} | 22 +- .../Collection/{HasCest.php => HasTest.php} | 12 +- ...xtRewindCest.php => KeyNextRewindTest.php} | 20 +- .../{ValidCest.php => ValidTest.php} | 14 +- ...DocBlockCest.php => ParseDocBlockTest.php} | 20 +- .../Reader/{ParseCest.php => ParseTest.php} | 309 +++++++++--------- .../{ConstructCest.php => ConstructTest.php} | 90 +++-- ...nsCest.php => GetClassAnnotationsTest.php} | 36 +- ...Cest.php => GetMethodsAnnotationsTest.php} | 64 ++-- ...t.php => GetPropertiesAnnotationsTest.php} | 64 ++-- ...DataCest.php => GetReflectionDataTest.php} | 12 +- 50 files changed, 1407 insertions(+), 868 deletions(-) create mode 100644 tests/support/data/fixtures/Annotations/Adapter/StreamEmptyDataFixture.php create mode 100644 tests/support/data/fixtures/Annotations/Adapter/StreamFileExistsFixture.php create mode 100644 tests/support/data/fixtures/Annotations/Adapter/StreamFixture.php create mode 100644 tests/support/data/fixtures/Annotations/Adapter/StreamWrongDataFixture.php create mode 100644 tests/support/data/fixtures/Annotations/TestClass.php create mode 100644 tests/support/data/fixtures/Annotations/TestClassNs.php create mode 100644 tests/support/data/fixtures/Annotations/TestInvalid.php create mode 100644 tests/support/data/fixtures/Traits/AnnotationsTrait2.php rename tests/unit/Annotations/Adapter/{ConstructCest.php => ConstructTest.php} (55%) create mode 100644 tests/unit/Annotations/Adapter/GetConstantsTest.php delete mode 100644 tests/unit/Annotations/Adapter/GetMethodCest.php delete mode 100644 tests/unit/Annotations/Adapter/GetMethodsCest.php create mode 100644 tests/unit/Annotations/Adapter/GetMethodsTest.php rename tests/unit/Annotations/Adapter/{GetPropertiesCest.php => GetPropertiesTest.php} (59%) rename tests/unit/Annotations/Adapter/{GetPropertyCest.php => GetPropertyTest.php} (54%) rename tests/unit/Annotations/Adapter/{GetSetReaderCest.php => GetSetReaderTest.php} (56%) rename tests/unit/Annotations/Adapter/{GetCest.php => GetTest.php} (59%) delete mode 100644 tests/unit/Annotations/Adapter/ReadWriteCest.php create mode 100644 tests/unit/Annotations/Adapter/ReadWriteTest.php rename tests/unit/Annotations/Annotation/{ConstructCest.php => ConstructTest.php} (77%) rename tests/unit/Annotations/Annotation/{GetArgumentCest.php => GetArgumentTest.php} (79%) rename tests/unit/Annotations/Annotation/{GetArgumentsCest.php => GetArgumentsTest.php} (82%) rename tests/unit/Annotations/Annotation/{GetExprArgumentsCest.php => GetExprArgumentsTest.php} (81%) delete mode 100644 tests/unit/Annotations/Annotation/GetExpressionCest.php create mode 100644 tests/unit/Annotations/Annotation/GetExpressionTest.php rename tests/unit/Annotations/Annotation/{GetNameCest.php => GetNameTest.php} (75%) rename tests/unit/Annotations/Annotation/{GetNamedArgumentCest.php => GetNamedArgumentTest.php} (88%) rename tests/unit/Annotations/Annotation/{GetNamedParameterCest.php => GetNamedParameterTest.php} (87%) rename tests/unit/Annotations/Annotation/{HasArgumentCest.php => HasArgumentTest.php} (77%) rename tests/unit/Annotations/Annotation/{NumberArgumentsCest.php => NumberArgumentsTest.php} (82%) rename tests/unit/Annotations/AnnotationsFactory/{LoadCest.php => LoadTest.php} (60%) rename tests/unit/Annotations/AnnotationsFactory/{NewInstanceCest.php => NewInstanceTest.php} (50%) rename tests/unit/Annotations/Collection/{ConstructCest.php => ConstructTest.php} (71%) rename tests/unit/Annotations/Collection/{CountCest.php => CountTest.php} (81%) rename tests/unit/Annotations/Collection/{CurrentCest.php => CurrentTest.php} (73%) rename tests/unit/Annotations/Collection/{GetAllCest.php => GetAllTest.php} (86%) rename tests/unit/Annotations/Collection/{GetAnnotationsCest.php => GetAnnotationsTest.php} (86%) rename tests/unit/Annotations/Collection/{GetCest.php => GetTest.php} (72%) rename tests/unit/Annotations/Collection/{HasCest.php => HasTest.php} (81%) rename tests/unit/Annotations/Collection/{KeyNextRewindCest.php => KeyNextRewindTest.php} (76%) rename tests/unit/Annotations/Collection/{ValidCest.php => ValidTest.php} (80%) rename tests/unit/Annotations/Reader/{ParseDocBlockCest.php => ParseDocBlockTest.php} (88%) rename tests/unit/Annotations/Reader/{ParseCest.php => ParseTest.php} (67%) rename tests/unit/Annotations/Reflection/{ConstructCest.php => ConstructTest.php} (66%) rename tests/unit/Annotations/Reflection/{GetClassAnnotationsCest.php => GetClassAnnotationsTest.php} (72%) rename tests/unit/Annotations/Reflection/{GetMethodsAnnotationsCest.php => GetMethodsAnnotationsTest.php} (68%) rename tests/unit/Annotations/Reflection/{GetPropertiesAnnotationsCest.php => GetPropertiesAnnotationsTest.php} (68%) rename tests/unit/Annotations/Reflection/{GetReflectionDataCest.php => GetReflectionDataTest.php} (70%) diff --git a/tests/support/data/fixtures/Annotations/Adapter/StreamEmptyDataFixture.php b/tests/support/data/fixtures/Annotations/Adapter/StreamEmptyDataFixture.php new file mode 100644 index 000000000..2f6106940 --- /dev/null +++ b/tests/support/data/fixtures/Annotations/Adapter/StreamEmptyDataFixture.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +namespace MyLibrary\Tests\support\data\fixtures\Annotations\Adapter; + +use Phalcon\Annotations\Adapter\Stream; + +class StreamEmptyDataFixture extends Stream +{ + /** + * @param string $filename + * + * @return bool + * + * @link https://php.net/manual/en/function.file-exists.php + */ + protected function phpFileExists(string $filename) + { + return true; + } + + /** + * @param string $filename + * + * @return string|false + * + * @link https://php.net/manual/en/function.file-get-contents.php + */ + protected function phpFileGetContents(string $filename) + { + return ''; + } +} diff --git a/tests/support/data/fixtures/Annotations/Adapter/StreamFileExistsFixture.php b/tests/support/data/fixtures/Annotations/Adapter/StreamFileExistsFixture.php new file mode 100644 index 000000000..e2e9d0b23 --- /dev/null +++ b/tests/support/data/fixtures/Annotations/Adapter/StreamFileExistsFixture.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +namespace Phalcon\Tests1\Fixtures\Annotations\Adapter; + +use Phalcon\Annotations\Adapter\Stream; + +class StreamFileExistsFixture extends Stream +{ + /** + * @param string $filename + * + * @return bool + * + * @link https://php.net/manual/en/function.file-exists.php + */ + protected function phpFileExists(string $filename) + { + return false; + } +} diff --git a/tests/support/data/fixtures/Annotations/Adapter/StreamFixture.php b/tests/support/data/fixtures/Annotations/Adapter/StreamFixture.php new file mode 100644 index 000000000..a0a663de1 --- /dev/null +++ b/tests/support/data/fixtures/Annotations/Adapter/StreamFixture.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +namespace Phalcon\Tests1\Fixtures\Annotations\Adapter; + +use Phalcon\Annotations\Adapter\Stream; + +class StreamFixture extends Stream +{ + /** + * @param string $filename + * @param mixed $data + * @param int $flags + * @param resource $context + * + * @return int|false + * + * @link https://php.net/manual/en/function.file-put-contents.php + */ + protected function phpFilePutContents( + string $filename, + $data, + int $flags = 0, + $context = null + ) { + return false; + } +} diff --git a/tests/support/data/fixtures/Annotations/Adapter/StreamWrongDataFixture.php b/tests/support/data/fixtures/Annotations/Adapter/StreamWrongDataFixture.php new file mode 100644 index 000000000..aed091afa --- /dev/null +++ b/tests/support/data/fixtures/Annotations/Adapter/StreamWrongDataFixture.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +namespace MyLibrary\Tests\support\data\fixtures\Annotations\Adapter; + +use Phalcon\Annotations\Adapter\Stream; + +class StreamWrongDataFixture extends Stream +{ + /** + * @param string $filename + * + * @return bool + * + * @link https://php.net/manual/en/function.file-exists.php + */ + protected function phpFileExists(string $filename) + { + return true; + } + + /** + * @param string $filename + * + * @return string|false + * + * @link https://php.net/manual/en/function.file-get-contents.php + */ + protected function phpFileGetContents(string $filename) + { + return '{a:1'; + } +} diff --git a/tests/support/data/fixtures/Annotations/TestClass.php b/tests/support/data/fixtures/Annotations/TestClass.php new file mode 100644 index 000000000..b2560536b --- /dev/null +++ b/tests/support/data/fixtures/Annotations/TestClass.php @@ -0,0 +1,125 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +/** + * TestClass + * + * This is a test class, it's useful to make tests + * + * @Simple + * @SingleParam("Param") + * @MultipleParams("First", Second, 1, 1.1, -10, false, true, null) + * @Params({"key1", "key2", "key3"}); + * @HashParams({"key1": "value", "key2": "value", "key3": "value"}); + * @NamedParams(first=some, second=other); + * @AlternativeNamedParams(first: some, second: other); + * @AlternativeHashParams({key1="value", "key2"=value, "key3"="value"}); + * @RecursiveHash({key1="value", "key2"=value, "key3"=[1, 2, 3, 4]}); + */ +class TestClass +{ + /** + * @Simple + */ + const TEST_CONST1 = 'test-const-with-annotation'; + + const TEST_CONST2 = 'test-const-without-annotation'; + + /** + * This is a property string + * + * @var string + * @Simple + * @SingleParam("Param") + * @MultipleParams("First", Second, 1, 1.1, -10, false, true, null) + */ + public $testProp1; + + /** + * + */ + public $testProp2; + + /** + * @Simple @SingleParam("Param") @MultipleParams("First", Second, 1, 1.1, + * -10, false, true, null) + */ + public $testProp3; + + /** + * @Simple @SingleParam( + * "Param") @MultipleParams( "First", + * Second, 1, 1.1 + * ,-10, + * false, true, + * null) + */ + public $testProp4; + + public $testProp5; + + /** + * This is a comment + */ + public $testProp6; + + /** + * This is a property string + * + * @return string + * @Simple + * @SingleParam("Param") + * @MultipleParams("First", Second, 1, 1.1, -10, false, true, null) + * @NamedMultipleParams(first: "First", second: Second) + */ + public function testMethod1() + { + } + + /** + * + */ + public function testMethod2() + { + } + + /** + * @Simple @SingleParam("Param") @MultipleParams("First", Second, 1, 1.1, + * -10, false, true, null) + */ + public function testMethod3() + { + } + + /** + * @Simple @SingleParam( + * "Param") @MultipleParams( "First", + * Second, 1, 1.1 + * ,-10, + * false, true, + * null) + */ + public function testMethod4() + { + } + + /** @Simple a good comment between annotations @SingleParam( + * "Param") this is extra content @MultipleParams( "First", + * Second, 1, 1.1 ,-10, + * false, true, + * null) more content here + */ + public function testMethod5() + { + } +} diff --git a/tests/support/data/fixtures/Annotations/TestClassNs.php b/tests/support/data/fixtures/Annotations/TestClassNs.php new file mode 100644 index 000000000..ddf6fdb65 --- /dev/null +++ b/tests/support/data/fixtures/Annotations/TestClassNs.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace User; + +/** + * User\TestClassNs + * + * This class has annotations but it's in a namespace + * + * @Simple + * @SingleParam("Param") + * @MultipleParams("First", Second, 1, 1.1, -10, false, true, null) + * @Params({"key1", "key2", "key3"}); + * @HashParams({"key1": "value", "key2": "value", "key3": "value"}); + * @NamedParams(first=some, second=other); + * @AlternativeNamedParams(first: some, second: other); + * @AlternativeHashParams({key1="value", "key2"=value, "key3"="value"}); + * @RecursiveHash({key1="value", "key2"=value, "key3"=[1, 2, 3, 4]}); + */ +class TestClassNs +{ +} diff --git a/tests/support/data/fixtures/Annotations/TestInvalid.php b/tests/support/data/fixtures/Annotations/TestInvalid.php new file mode 100644 index 000000000..d1e1d9936 --- /dev/null +++ b/tests/support/data/fixtures/Annotations/TestInvalid.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +/** + * @Invalid( + */ +class TestInvalid +{ +} diff --git a/tests/support/data/fixtures/Traits/AnnotationsTrait2.php b/tests/support/data/fixtures/Traits/AnnotationsTrait2.php new file mode 100644 index 000000000..fcaf6dd3a --- /dev/null +++ b/tests/support/data/fixtures/Traits/AnnotationsTrait2.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Phalcon\Tests1\Fixtures\Traits; + +use Phalcon\Annotations\Adapter\Apcu; +use Phalcon\Annotations\Adapter\Memory; +use Phalcon\Annotations\Adapter\Stream; + +use function outputDir; +use function outputDir2; + +trait AnnotationsTrait2 +{ + public static function providerExamples(): array + { + return [ + [ + Apcu::class, + [ + 'prefix' => 'nova_prefix', + 'lifetime' => 3600, + ], + ], + [ + Memory::class, + [], + ], + [ + Stream::class, + [ + 'annotationsDir' => outputDir2('annotations/'), + ], + ], + ]; + } +} diff --git a/tests/unit/Acl/Adapter/Memory/AddRoleTest.php b/tests/unit/Acl/Adapter/Memory/AddRoleTest.php index 2750670e8..413eed4db 100644 --- a/tests/unit/Acl/Adapter/Memory/AddRoleTest.php +++ b/tests/unit/Acl/Adapter/Memory/AddRoleTest.php @@ -112,7 +112,7 @@ public function testAclAdapterMemoryAddRoleException(): void { $this->expectException(Exception::class); $this->expectExceptionMessage( - 'Role must be either a string or implement RoleInterface' + 'Role must be either a string or implement RoleInterface' ); $acl = new Memory(); diff --git a/tests/unit/Acl/Adapter/Memory/IsAllowedTest.php b/tests/unit/Acl/Adapter/Memory/IsAllowedTest.php index 0c17a1df6..a3c61a90c 100644 --- a/tests/unit/Acl/Adapter/Memory/IsAllowedTest.php +++ b/tests/unit/Acl/Adapter/Memory/IsAllowedTest.php @@ -30,7 +30,6 @@ use function ob_end_clean; use function ob_get_contents; use function ob_start; - use function restore_error_handler; use const E_USER_WARNING; diff --git a/tests/unit/Annotations/Adapter/ConstructCest.php b/tests/unit/Annotations/Adapter/ConstructTest.php similarity index 55% rename from tests/unit/Annotations/Adapter/ConstructCest.php rename to tests/unit/Annotations/Adapter/ConstructTest.php index e191baf4b..0090eaa12 100644 --- a/tests/unit/Annotations/Adapter/ConstructCest.php +++ b/tests/unit/Annotations/Adapter/ConstructTest.php @@ -13,97 +13,76 @@ namespace Phalcon\Tests\Unit\Annotations\Adapter; -use Codeception\Example; use Phalcon\Annotations\Adapter\AdapterInterface; use Phalcon\Annotations\Collection; use Phalcon\Annotations\Reflection; -use Phalcon\Tests\Fixtures\Traits\AnnotationsTrait; +use Phalcon\Tests1\Fixtures\Traits\AnnotationsTrait2; +use PHPUnit\Framework\TestCase; use TestClass; -use UnitTester; use User\TestClassNs; -use function dataDir; +use function dataDir2; use function is_object; -class ConstructCest +final class ConstructTest extends TestCase { - use AnnotationsTrait; + use AnnotationsTrait2; /** - * Tests Phalcon\Annotations\Adapter :: __construct() + * Tests Phalcon\Annotations\Adapter :: * - * @dataProvider getExamples + * @dataProvider providerExamples * - * @author Phalcon Team - * @since 2022-12-30 - */ - public function annotationsAdapterConstruct(UnitTester $I, Example $example) - { - $I->wantToTest('Annotations\Adapter __construct()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $class = $example['class']; - $params = $example['params']; - $adapter = new $class($params); - - $expected = AdapterInterface::class; - $actual = $adapter; - $I->assertInstanceOf($expected, $actual); - } - - /** - * Tests Phalcon\Annotations\Adapter :: + * @param string $class + * @param array $params * - * @dataProvider getExamples + * @return void * * @author Phalcon Team * @since 2022-12-30 */ - public function annotationsAdapter(UnitTester $I, Example $example) - { - $I->wantToTest('Annotations\Adapter'); - - $I->seeFileFound( - dataDir('fixtures/Annotations/TestClass.php') + public function testAnnotationsAdapter( + string $class, + array $params + ): void { + $this->assertFileExists( + dataDir2('fixtures/Annotations/TestClass.php') ); - $I->seeFileFound( - dataDir('fixtures/Annotations/TestClassNs.php') + $this->assertFileExists( + dataDir2('fixtures/Annotations/TestClassNs.php') ); - require_once dataDir('fixtures/Annotations/TestClass.php'); - require_once dataDir('fixtures/Annotations/TestClassNs.php'); + require_once dataDir2('fixtures/Annotations/TestClass.php'); + require_once dataDir2('fixtures/Annotations/TestClassNs.php'); - $class = $example['class']; - $params = $example['params']; $adapter = new $class($params); $classAnnotations = $adapter->get(TestClass::class); $actual = is_object($classAnnotations); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = Reflection::class; $actual = $classAnnotations; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $expected = Collection::class; $actual = $classAnnotations->getClassAnnotations(); - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $classAnnotations = $adapter->get(TestClassNs::class); $actual = is_object($classAnnotations); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = Reflection::class; $actual = $classAnnotations; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $expected = Collection::class; $actual = $classAnnotations->getClassAnnotations(); - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $property = $adapter->getProperty( @@ -112,14 +91,40 @@ public function annotationsAdapter(UnitTester $I, Example $example) ); $actual = is_object($property); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = Collection::class; $actual = $property; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $expected = 4; $actual = $property->count(); - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Annotations\Adapter :: __construct() + * + * @dataProvider providerExamples + * + * @param string $class + * @param array $params + * + * @return void + * + * @author Phalcon Team + * @since 2022-12-30 + */ + public function testAnnotationsAdapterConstruct( + string $class, + array $params + ): void { + require_once dataDir2('fixtures/Annotations/TestClass.php'); + + $adapter = new $class($params); + + $expected = AdapterInterface::class; + $actual = $adapter; + $this->assertInstanceOf($expected, $actual); } } diff --git a/tests/unit/Annotations/Adapter/GetConstantsTest.php b/tests/unit/Annotations/Adapter/GetConstantsTest.php new file mode 100644 index 000000000..e091ff8bf --- /dev/null +++ b/tests/unit/Annotations/Adapter/GetConstantsTest.php @@ -0,0 +1,96 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Phalcon\Tests\Unit\Annotations\Adapter; + +use Phalcon\Annotations\Collection; +use Phalcon\Tests1\Fixtures\Traits\AnnotationsTrait2; +use PHPUnit\Framework\TestCase; +use TestClass; + +use function array_keys; +use function dataDir2; +use function outputDir2; +use function safeDeleteFile2; + +final class GetConstantsTest extends TestCase +{ + use AnnotationsTrait2; + + /** + * Tests Phalcon\Annotations\Adapter :: getMethod() + * + * @dataProvider providerExamples + * + * @param string $class + * @param array $params + * + * @return void + * + * @author Phalcon Team + * @since 2022-12-30 + */ + public function testAnnotationsAdapterGetConstant( + string $class, + array $params + ): void { + require_once dataDir2('fixtures/Annotations/TestClass.php'); + + $adapter = new $class($params); + + $constantAnnotation = $adapter->getConstant( + TestClass::class, + 'TEST_CONST1' + ); + + $expected = Collection::class; + $actual = $constantAnnotation; + $this->assertInstanceOf($expected, $actual); + + safeDeleteFile2(outputDir2('annotations/testclass.php')); + } + + /** + * Tests Phalcon\Annotations\Adapter :: getMethods() + * + * @dataProvider providerExamples + * + * @param string $class + * @param array $params + * + * @return void + * + * @author Phalcon Team + * @since 2022-12-30 + */ + public function testAnnotationsAdapterGetConstants( + string $class, + array $params + ): void { + require_once dataDir2('fixtures/Annotations/TestClass.php'); + + $adapter = new $class($params); + + $constantAnnotations = $adapter->getConstants( + TestClass::class + ); + + $expected = [ + 'TEST_CONST1', + ]; + $actual = array_keys($constantAnnotations); + $this->assertSame($expected, $actual); + + safeDeleteFile2(outputDir2('annotations/testclass.php')); + } +} diff --git a/tests/unit/Annotations/Adapter/GetMethodCest.php b/tests/unit/Annotations/Adapter/GetMethodCest.php deleted file mode 100644 index 3b8ce45e8..000000000 --- a/tests/unit/Annotations/Adapter/GetMethodCest.php +++ /dev/null @@ -1,57 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE.txt - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Phalcon\Tests\Unit\Annotations\Adapter; - -use Codeception\Example; -use Phalcon\Annotations\Collection; -use Phalcon\Tests\Fixtures\Traits\AnnotationsTrait; -use TestClass; -use UnitTester; - -use function dataDir; - -class GetMethodCest -{ - use AnnotationsTrait; - - /** - * Tests Phalcon\Annotations\Adapter :: getMethod() - * - * @dataProvider getExamples - * - * @author Phalcon Team - * @since 2022-12-30 - */ - public function annotationsAdapterGetMethod(UnitTester $I, Example $example) - { - $I->wantToTest('Annotations\Adapter getMethod()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $class = $example['class']; - $params = $example['params']; - $adapter = new $class($params); - - $methodAnnotation = $adapter->getMethod( - TestClass::class, - 'testMethod1' - ); - - $expected = Collection::class; - $actual = $methodAnnotation; - $I->assertInstanceOf($expected, $actual); - - $I->safeDeleteFile('testclass.php'); - } -} diff --git a/tests/unit/Annotations/Adapter/GetMethodsCest.php b/tests/unit/Annotations/Adapter/GetMethodsCest.php deleted file mode 100644 index 11eb46180..000000000 --- a/tests/unit/Annotations/Adapter/GetMethodsCest.php +++ /dev/null @@ -1,71 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE.txt - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Phalcon\Tests\Unit\Annotations\Adapter; - -use Codeception\Example; -use Phalcon\Annotations\Collection; -use Phalcon\Tests\Fixtures\Traits\AnnotationsTrait; -use TestClass; -use UnitTester; - -use function array_keys; -use function dataDir; - -class GetMethodsCest -{ - use AnnotationsTrait; - - /** - * Tests Phalcon\Annotations\Adapter :: getMethods() - * - * @dataProvider getExamples - * - * @author Phalcon Team - * @since 2022-12-30 - */ - public function annotationsAdapterGetMethods( - UnitTester $I, - Example $example - ) { - $I->wantToTest('Annotations\Adapter getMethods()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $class = $example['class']; - $params = $example['params']; - $adapter = new $class($params); - - $methodAnnotations = $adapter->getMethods( - TestClass::class - ); - - $keys = array_keys($methodAnnotations); - $expected = [ - 'testMethod1', - 'testMethod3', - 'testMethod4', - 'testMethod5', - ]; - $actual = $keys; - $I->assertSame($expected, $actual); - - foreach ($methodAnnotations as $methodAnnotation) { - $expected = Collection::class; - $actual = $methodAnnotation; - $I->assertInstanceOf($expected, $actual); - } - - $I->safeDeleteFile('testclass.php'); - } -} diff --git a/tests/unit/Annotations/Adapter/GetMethodsTest.php b/tests/unit/Annotations/Adapter/GetMethodsTest.php new file mode 100644 index 000000000..f96fb92a0 --- /dev/null +++ b/tests/unit/Annotations/Adapter/GetMethodsTest.php @@ -0,0 +1,115 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Phalcon\Tests\Unit\Annotations\Adapter; + +use Phalcon\Annotations\Collection; +use Phalcon\Tests1\Fixtures\Traits\AnnotationsTrait2; +use PHPUnit\Framework\TestCase; +use TestClass; + +use function array_keys; +use function dataDir2; +use function outputDir2; +use function safeDeleteFile2; + +final class GetMethodsTest extends TestCase +{ + use AnnotationsTrait2; + + /** + * Tests Phalcon\Annotations\Adapter :: getMethod() + * + * @dataProvider providerExamples + * + * @param string $class + * @param array $params + * + * @return void + * + * @author Phalcon Team + * @since 2022-12-30 + */ + public function testAnnotationsAdapterGetMethod( + string $class, + array $params + ): void { + require_once dataDir2('fixtures/Annotations/TestClass.php'); + + $adapter = new $class($params); + + $methodAnnotation = $adapter->getMethod( + TestClass::class, + 'testMethod1' + ); + + $expected = Collection::class; + $actual = $methodAnnotation; + $this->assertInstanceOf($expected, $actual); + + $methodAnnotation = $adapter->getMethod( + TestClass::class, + 'testMethodUnknown' + ); + + $expected = Collection::class; + $actual = $methodAnnotation; + $this->assertInstanceOf($expected, $actual); + + safeDeleteFile2(outputDir2('annotations/testclass.php')); + } + + /** + * Tests Phalcon\Annotations\Adapter :: getMethods() + * + * @dataProvider providerExamples + * + * @param string $class + * @param array $params + * + * @return void + * + * @author Phalcon Team + * @since 2022-12-30 + */ + public function testAnnotationsAdapterGetMethods( + string $class, + array $params + ): void { + require_once dataDir2('fixtures/Annotations/TestClass.php'); + + $adapter = new $class($params); + + $methodAnnotations = $adapter->getMethods( + TestClass::class + ); + + $keys = array_keys($methodAnnotations); + $expected = [ + 'testMethod1', + 'testMethod3', + 'testMethod4', + 'testMethod5', + ]; + $actual = $keys; + $this->assertSame($expected, $actual); + + foreach ($methodAnnotations as $methodAnnotation) { + $expected = Collection::class; + $actual = $methodAnnotation; + $this->assertInstanceOf($expected, $actual); + } + + safeDeleteFile2(outputDir2('annotations/testclass.php')); + } +} diff --git a/tests/unit/Annotations/Adapter/GetPropertiesCest.php b/tests/unit/Annotations/Adapter/GetPropertiesTest.php similarity index 59% rename from tests/unit/Annotations/Adapter/GetPropertiesCest.php rename to tests/unit/Annotations/Adapter/GetPropertiesTest.php index 4a10a2112..da5b82e57 100644 --- a/tests/unit/Annotations/Adapter/GetPropertiesCest.php +++ b/tests/unit/Annotations/Adapter/GetPropertiesTest.php @@ -13,37 +13,39 @@ namespace Phalcon\Tests\Unit\Annotations\Adapter; -use Codeception\Example; use Phalcon\Annotations\Collection; -use Phalcon\Tests\Fixtures\Traits\AnnotationsTrait; +use Phalcon\Tests1\Fixtures\Traits\AnnotationsTrait2; +use PHPUnit\Framework\TestCase; use TestClass; -use UnitTester; use function array_keys; -use function dataDir; +use function dataDir2; +use function outputDir2; +use function safeDeleteFile2; -class GetPropertiesCest +final class GetPropertiesTest extends TestCase { - use AnnotationsTrait; + use AnnotationsTrait2; /** * Tests Phalcon\Annotations\Adapter :: getProperties() * - * @dataProvider getExamples + * @dataProvider providerExamples + * + * @param string $class + * @param array $params + * + * @return void * * @author Phalcon Team * @since 2022-12-30 */ - public function annotationsAdapterGetProperties( - UnitTester $I, - Example $example - ) { - $I->wantToTest('Annotations\Adapter getProperties()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); + public function testAnnotationsAdapterGetProperties( + string $class, + array $params + ): void { + require_once dataDir2('fixtures/Annotations/TestClass.php'); - $class = $example['class']; - $params = $example['params']; $adapter = new $class($params); $propertyAnnotations = $adapter->getProperties(TestClass::class); @@ -55,14 +57,14 @@ public function annotationsAdapterGetProperties( 'testProp4', ]; $actual = $keys; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); foreach ($propertyAnnotations as $propertyAnnotation) { $expected = Collection::class; $actual = $propertyAnnotation; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); } - $I->safeDeleteFile('testclass.php'); + safeDeleteFile2(outputDir2('annotations/testclass.php')); } } diff --git a/tests/unit/Annotations/Adapter/GetPropertyCest.php b/tests/unit/Annotations/Adapter/GetPropertyTest.php similarity index 54% rename from tests/unit/Annotations/Adapter/GetPropertyCest.php rename to tests/unit/Annotations/Adapter/GetPropertyTest.php index b27eb1fa5..139655379 100644 --- a/tests/unit/Annotations/Adapter/GetPropertyCest.php +++ b/tests/unit/Annotations/Adapter/GetPropertyTest.php @@ -13,36 +13,38 @@ namespace Phalcon\Tests\Unit\Annotations\Adapter; -use Codeception\Example; use Phalcon\Annotations\Collection; -use Phalcon\Tests\Fixtures\Traits\AnnotationsTrait; +use Phalcon\Tests1\Fixtures\Traits\AnnotationsTrait2; +use PHPUnit\Framework\TestCase; use TestClass; -use UnitTester; -use function dataDir; +use function dataDir2; +use function outputDir2; +use function safeDeleteFile2; -class GetPropertyCest +final class GetPropertyTest extends TestCase { - use AnnotationsTrait; + use AnnotationsTrait2; /** * Tests Phalcon\Annotations\Adapter :: getProperty() * - * @dataProvider getExamples + * @dataProvider providerExamples + * + * @param string $class + * @param array $params + * + * @return void * * @author Phalcon Team * @since 2022-12-30 */ - public function annotationsAdapterGetProperty( - UnitTester $I, - Example $example - ) { - $I->wantToTest('Annotations\Adapter getProperty()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); + public function testAnnotationsAdapterGetProperty( + string $class, + array $params + ): void { + require_once dataDir2('fixtures/Annotations/TestClass.php'); - $class = $example['class']; - $params = $example['params']; $adapter = new $class($params); $propertyAnnotation = $adapter->getProperty( @@ -52,8 +54,8 @@ public function annotationsAdapterGetProperty( $expected = Collection::class; $actual = $propertyAnnotation; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); - $I->safeDeleteFile('testclass.php'); + safeDeleteFile2(outputDir2('annotations/') . 'testclass.php'); } } diff --git a/tests/unit/Annotations/Adapter/GetSetReaderCest.php b/tests/unit/Annotations/Adapter/GetSetReaderTest.php similarity index 56% rename from tests/unit/Annotations/Adapter/GetSetReaderCest.php rename to tests/unit/Annotations/Adapter/GetSetReaderTest.php index 8e7f4882f..e7d4feba9 100644 --- a/tests/unit/Annotations/Adapter/GetSetReaderCest.php +++ b/tests/unit/Annotations/Adapter/GetSetReaderTest.php @@ -13,35 +13,35 @@ namespace Phalcon\Tests\Unit\Annotations\Adapter; -use Codeception\Example; use Phalcon\Annotations\Reader; -use Phalcon\Tests\Fixtures\Traits\AnnotationsTrait; -use UnitTester; +use Phalcon\Tests1\Fixtures\Traits\AnnotationsTrait2; +use PHPUnit\Framework\TestCase; -use function dataDir; +use function dataDir2; -class GetSetReaderCest +final class GetSetReaderTest extends TestCase { - use AnnotationsTrait; + use AnnotationsTrait2; /** * Tests Phalcon\Annotations\Adapter :: getReader()/setReader() * - * @dataProvider getExamples + * @dataProvider providerExamples + * + * @param string $class + * @param array $params + * + * @return void * * @author Phalcon Team * @since 2022-12-30 */ - public function annotationsAdapterGetSetReader( - UnitTester $I, - Example $example - ) { - $I->wantToTest('Annotations\Adapter getReader()/setReader()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); + public function testAnnotationsAdapterGetSetReader( + string $class, + array $params + ): void { + require_once dataDir2('fixtures/Annotations/TestClass.php'); - $class = $example['class']; - $params = $example['params']; $adapter = new $class($params); $reader = new Reader(); @@ -49,10 +49,10 @@ public function annotationsAdapterGetSetReader( $expected = $reader; $actual = $adapter->getReader(); - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = Reader::class; $actual = $adapter->getReader(); - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); } } diff --git a/tests/unit/Annotations/Adapter/GetCest.php b/tests/unit/Annotations/Adapter/GetTest.php similarity index 59% rename from tests/unit/Annotations/Adapter/GetCest.php rename to tests/unit/Annotations/Adapter/GetTest.php index c20c902f0..b9ed418b8 100644 --- a/tests/unit/Annotations/Adapter/GetCest.php +++ b/tests/unit/Annotations/Adapter/GetTest.php @@ -13,46 +13,50 @@ namespace Phalcon\Tests\Unit\Annotations\Adapter; -use Codeception\Example; use Phalcon\Annotations\Collection; use Phalcon\Annotations\Reflection; -use Phalcon\Tests\Fixtures\Traits\AnnotationsTrait; +use Phalcon\Tests1\Fixtures\Traits\AnnotationsTrait2; +use PHPUnit\Framework\TestCase; use TestClass; -use UnitTester; -class GetCest +use function dataDir2; + +final class GetTest extends TestCase { - use AnnotationsTrait; + use AnnotationsTrait2; /** * Tests Phalcon\Annotations\Adapter :: get() * - * @dataProvider getExamples + * @dataProvider providerExamples + * + * @param string $class + * @param array $params + * + * @return void * * @author Phalcon Team * @since 2022-12-30 */ - public function annotationsAdapterGet(UnitTester $I, Example $example) - { - $I->wantToTest('Annotations\Adapter get()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); + public function testAnnotationsAdapterGet( + string $class, + array $params + ): void { + require_once dataDir2('fixtures/Annotations/TestClass.php'); - $class = $example['class']; - $params = $example['params']; $adapter = new $class($params); $classAnnotations = $adapter->get(TestClass::class); $actual = is_object($classAnnotations); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = Reflection::class; $actual = $classAnnotations; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $expected = Collection::class; $actual = $classAnnotations->getClassAnnotations(); - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); } } diff --git a/tests/unit/Annotations/Adapter/ReadWriteCest.php b/tests/unit/Annotations/Adapter/ReadWriteCest.php deleted file mode 100644 index f79436b83..000000000 --- a/tests/unit/Annotations/Adapter/ReadWriteCest.php +++ /dev/null @@ -1,63 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE.txt - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Phalcon\Tests\Unit\Annotations\Adapter; - -use Codeception\Example; -use Phalcon\Annotations\Reflection; -use Phalcon\Tests\Fixtures\Traits\AnnotationsTrait; -use TestClass; -use UnitTester; - -use function dataDir; -use function outputDir; - -class ReadWriteCest -{ - use AnnotationsTrait; - - /** - * Tests Phalcon\Annotations\Adapter :: read()/write() - * - * @dataProvider getExamples - * - * @author Phalcon Team - * @since 2022-12-30 - */ - public function annotationsAdapterReadWrite(UnitTester $I, Example $example) - { - $I->wantToTest('Annotations\Adapter read()/write()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $class = $example['class']; - $params = $example['params']; - $adapter = new $class($params); - - $classAnnotations = $adapter->get(TestClass::class); - - $adapter->write('testwrite', $classAnnotations); - - $I->assertFileExists( - outputDir('tests/annotations/testclass.php') - ); - - $newClass = $adapter->read('testwrite'); - $expected = Reflection::class; - $actual = $newClass; - $I->assertInstanceOf($expected, $actual); - - $I->safeDeleteFile('testwrite.php'); - $I->safeDeleteFile('testclass.php'); - } -} diff --git a/tests/unit/Annotations/Adapter/ReadWriteTest.php b/tests/unit/Annotations/Adapter/ReadWriteTest.php new file mode 100644 index 000000000..74db4a6c6 --- /dev/null +++ b/tests/unit/Annotations/Adapter/ReadWriteTest.php @@ -0,0 +1,129 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Phalcon\Tests\Unit\Annotations\Adapter; + +use MyLibrary\Tests\support\data\fixtures\Annotations\Adapter\StreamEmptyDataFixture; +use MyLibrary\Tests\support\data\fixtures\Annotations\Adapter\StreamWrongDataFixture; +use Phalcon\Annotations\Adapter\Stream; +use Phalcon\Annotations\Exception; +use Phalcon\Annotations\Reflection; +use Phalcon\Tests1\Fixtures\Annotations\Adapter\StreamFileExistsFixture; +use Phalcon\Tests1\Fixtures\Annotations\Adapter\StreamFixture; +use Phalcon\Tests1\Fixtures\Traits\AnnotationsTrait2; +use PHPUnit\Framework\TestCase; +use RuntimeException; +use TestClass; + +use function dataDir2; +use function outputDir2; +use function safeDeleteFile2; + +final class ReadWriteTest extends TestCase +{ + use AnnotationsTrait2; + + /** + * Tests Phalcon\Annotations\Adapter :: read()/write() - exceptions + * + * @return void + * + * @author Phalcon Team + * @since 2022-12-30 + */ + public function testAnnotationsAdapterReadException(): void + { + require_once dataDir2('fixtures/Annotations/TestClass.php'); + + /** + * File does not exist + */ + $params = [ + 'annotationsDir' => outputDir2('annotations/'), + ]; + $adapter = new StreamFileExistsFixture($params); + + $actual = $adapter->read('testwrite'); + $this->assertFalse($actual); + + /** + * Empty file + */ + $adapter = new StreamEmptyDataFixture($params); + + $actual = $adapter->read('testwrite'); + $this->assertFalse($actual); + } + + /** + * Tests Phalcon\Annotations\Adapter :: read()/write() + * + * @dataProvider providerExamples + * + * @return void + * + * @author Phalcon Team + * @since 2022-12-30 + */ + public function testAnnotationsAdapterReadWrite(): void + { + require_once dataDir2('fixtures/Annotations/TestClass.php'); + + $params = [ + 'annotationsDir' => outputDir2('annotations/'), + ]; + $adapter = new Stream($params); + + $classAnnotations = $adapter->get(TestClass::class); + + $adapter->write('testwrite', $classAnnotations); + + $actual = outputDir2('annotations/testclass.php'); + $this->assertFileExists($actual); + + $newClass = $adapter->read('testwrite'); + $expected = Reflection::class; + $actual = $newClass; + $this->assertInstanceOf($expected, $actual); + + safeDeleteFile2(outputDir2('annotations/testwrite.php')); + safeDeleteFile2(outputDir2('annotations/testclass.php')); + } + + /** + * Tests Phalcon\Annotations\Adapter :: write() - stream exception + * + * @return void + * + * @author Phalcon Team + * @since 2022-12-30 + */ + public function testAnnotationsAdapterWriteStreamException(): void + { + require_once dataDir2('fixtures/Annotations/TestClass.php'); + + $params = [ + 'annotationsDir' => outputDir2('annotations/'), + ]; + $adapter = new StreamFixture($params); + + $this->expectException(Exception::class); + $this->expectExceptionMessage('Annotations directory cannot be written'); + $classAnnotations = $adapter->get(TestClass::class); + + $adapter->write('testwrite', $classAnnotations); + + safeDeleteFile2(outputDir2('annotations/testwrite.php')); + safeDeleteFile2(outputDir2('annotations/testclass.php')); + } +} diff --git a/tests/unit/Annotations/Annotation/ConstructCest.php b/tests/unit/Annotations/Annotation/ConstructTest.php similarity index 77% rename from tests/unit/Annotations/Annotation/ConstructCest.php rename to tests/unit/Annotations/Annotation/ConstructTest.php index 1567441d9..16522d895 100644 --- a/tests/unit/Annotations/Annotation/ConstructCest.php +++ b/tests/unit/Annotations/Annotation/ConstructTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Annotation; use Phalcon\Annotations\Annotation; -use UnitTester; +use PHPUnit\Framework\TestCase; -class ConstructCest +final class ConstructTest extends TestCase { /** * Tests Phalcon\Annotations\Annotation :: __construct() @@ -24,15 +24,13 @@ class ConstructCest * @author Jeremy PASTOURET * @since 2020-01-22 */ - public function annotationsAnnotationConstruct(UnitTester $I) + public function testAnnotationsAnnotationConstruct(): void { - $I->wantToTest('Annotations\Annotation - __construct()'); - $annotation = new Annotation([ 'name' => 'NovAnnotation', ]); - $I->assertInstanceOf( + $this->assertInstanceOf( Annotation::class, $annotation ); diff --git a/tests/unit/Annotations/Annotation/GetArgumentCest.php b/tests/unit/Annotations/Annotation/GetArgumentTest.php similarity index 79% rename from tests/unit/Annotations/Annotation/GetArgumentCest.php rename to tests/unit/Annotations/Annotation/GetArgumentTest.php index d14dd4d4a..f744ea38b 100644 --- a/tests/unit/Annotations/Annotation/GetArgumentCest.php +++ b/tests/unit/Annotations/Annotation/GetArgumentTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Annotation; use Phalcon\Annotations\Annotation; -use UnitTester; +use PHPUnit\Framework\TestCase; -class GetArgumentCest +final class GetArgumentTest extends TestCase { private $PHANNOT_T_STRING = 303; @@ -26,10 +26,8 @@ class GetArgumentCest * @author Jeremy PASTOURET * @since 2020-01-22 */ - public function annotationsAnnotationGetArgument(UnitTester $I) + public function testAnnotationsAnnotationGetArgument(): void { - $I->wantToTest('Annotations\Annotation - getArgument()'); - $value = 'test'; $value1 = 'test1'; @@ -51,8 +49,7 @@ public function annotationsAnnotationGetArgument(UnitTester $I) ], ]); - $I->assertSame($annotation->getArgument(0), $value); - - $I->assertSame($annotation->getArgument(1), $value1); + $this->assertSame($annotation->getArgument(0), $value); + $this->assertSame($annotation->getArgument(1), $value1); } } diff --git a/tests/unit/Annotations/Annotation/GetArgumentsCest.php b/tests/unit/Annotations/Annotation/GetArgumentsTest.php similarity index 82% rename from tests/unit/Annotations/Annotation/GetArgumentsCest.php rename to tests/unit/Annotations/Annotation/GetArgumentsTest.php index d1bbc8007..d7ed133ca 100644 --- a/tests/unit/Annotations/Annotation/GetArgumentsCest.php +++ b/tests/unit/Annotations/Annotation/GetArgumentsTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Annotation; use Phalcon\Annotations\Annotation; -use UnitTester; +use PHPUnit\Framework\TestCase; -class GetArgumentsCest +final class GetArgumentsTest extends TestCase { private $PHANNOT_T_STRING = 303; @@ -26,10 +26,8 @@ class GetArgumentsCest * @author Jeremy PASTOURET * @since 2020-01-22 */ - public function annotationsAnnotationGetArguments(UnitTester $I) + public function testAnnotationsAnnotationGetArguments(): void { - $I->wantToTest('Annotations\Annotation - getArguments()'); - $value = 'test'; $value1 = 'test1'; @@ -51,6 +49,6 @@ public function annotationsAnnotationGetArguments(UnitTester $I) ], ]); - $I->assertSame([$value, $value1], $annotation->getArguments()); + $this->assertSame([$value, $value1], $annotation->getArguments()); } } diff --git a/tests/unit/Annotations/Annotation/GetExprArgumentsCest.php b/tests/unit/Annotations/Annotation/GetExprArgumentsTest.php similarity index 81% rename from tests/unit/Annotations/Annotation/GetExprArgumentsCest.php rename to tests/unit/Annotations/Annotation/GetExprArgumentsTest.php index 589f37d57..63a92be1b 100644 --- a/tests/unit/Annotations/Annotation/GetExprArgumentsCest.php +++ b/tests/unit/Annotations/Annotation/GetExprArgumentsTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Annotation; use Phalcon\Annotations\Annotation; -use UnitTester; +use PHPUnit\Framework\TestCase; -class GetExprArgumentsCest +final class GetExprArgumentsTest extends TestCase { private $PHANNOT_T_STRING = 303; @@ -26,10 +26,8 @@ class GetExprArgumentsCest * @author Jeremy PASTOURET * @since 2020-01-22 */ - public function annotationsAnnotationGetExprArguments(UnitTester $I) + public function testAnnotationsAnnotationGetExprArguments(): void { - $I->wantToTest('Annotations\Annotation - getExprArguments()'); - $value = 'test'; $value1 = 'test1'; @@ -53,6 +51,6 @@ public function annotationsAnnotationGetExprArguments(UnitTester $I) 'arguments' => $expr, ]); - $I->assertSame($annotation->getExprArguments(), $expr); + $this->assertSame($annotation->getExprArguments(), $expr); } } diff --git a/tests/unit/Annotations/Annotation/GetExpressionCest.php b/tests/unit/Annotations/Annotation/GetExpressionCest.php deleted file mode 100644 index 692f8707f..000000000 --- a/tests/unit/Annotations/Annotation/GetExpressionCest.php +++ /dev/null @@ -1,63 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE.txt - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Phalcon\Tests\Unit\Annotations\Annotation; - -use Phalcon\Annotations\Annotation; -use UnitTester; - -class GetExpressionCest -{ - private $PHANNOT_T_STRING = 303; - - /** - * Tests Phalcon\Annotations\Annotation :: getExpression() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAnnotationGetExpression(UnitTester $I) - { - $I->wantToTest('Annotations\Annotation - getExpression()'); - - $value = 'test'; - $value1 = 'test1'; - - $oneExpr = [ - 'type' => $this->PHANNOT_T_STRING, - 'value' => $value, - ]; - - $twoExpr = [ - 'type' => $this->PHANNOT_T_STRING, - 'value' => $value1, - ]; - - $expr = [ - [ - 'expr' => $oneExpr, - ], - [ - 'expr' => $twoExpr, - ], - ]; - - $annotation = new Annotation([ - 'name' => 'NovAnnotation', - 'arguments' => $expr, - ]); - - $I->assertSame($annotation->GetExpression($oneExpr), $value); - $I->assertSame($annotation->GetExpression($twoExpr), $value1); - } -} diff --git a/tests/unit/Annotations/Annotation/GetExpressionTest.php b/tests/unit/Annotations/Annotation/GetExpressionTest.php new file mode 100644 index 000000000..5536a2515 --- /dev/null +++ b/tests/unit/Annotations/Annotation/GetExpressionTest.php @@ -0,0 +1,107 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Phalcon\Tests\Unit\Annotations\Annotation; + +use Phalcon\Annotations\Annotation; +use Phalcon\Annotations\Exception; +use PHPUnit\Framework\TestCase; + +use function uniqid; + +final class GetExpressionTest extends TestCase +{ + private int $PHANNOT_T_ANNOTATION = 300; + private int $PHANNOT_T_STRING = 303; + + /** + * Tests Phalcon\Annotations\Annotation :: getExpression() + * + * @author Jeremy PASTOURET + * @since 2020-01-22 + */ + public function testAnnotationsAnnotationGetExpression(): void + { + $value1 = uniqid('tst-'); + $value2 = uniqid('tst-'); + $value3 = uniqid('tst-'); + + $expr1 = [ + 'type' => $this->PHANNOT_T_STRING, + 'value' => $value1, + ]; + + $expr2 = [ + 'type' => $this->PHANNOT_T_STRING, + 'value' => $value2, + ]; + + $expr3 = [ + 'type' => $this->PHANNOT_T_ANNOTATION, + 'value' => $value3, + ]; + + $expr4 = [ + 'type' => 99999, + 'value' => $value3, + ]; + + $expr = [ + [ + 'expr' => $expr1, + ], + [ + 'expr' => $expr2, + ], + [ + 'expr' => $expr3, + ], + ]; + + $annotation = new Annotation( + [ + 'name' => 'NovAnnotation', + 'arguments' => $expr, + ] + ); + + $expected = $value1; + $actual = $annotation->getExpression($expr1); + $this->assertSame($expected, $actual); + + $expected = $value2; + $actual = $annotation->getExpression($expr2); + $this->assertSame($expected, $actual); + + $expected = Annotation::class; + $actual = $annotation->getExpression($expr3); + $this->assertInstanceOf($expected, $actual); + + $this->expectException(Exception::class); + $this->expectExceptionMessage('The expression 99999 is unknown'); + $expr = [ + [ + 'expr' => $expr4, + ], + ]; + + $annotation = new Annotation( + [ + 'name' => 'NovAnnotation', + 'arguments' => $expr, + ] + ); + + $actual = $annotation->getExpression($expr4); + } +} diff --git a/tests/unit/Annotations/Annotation/GetNameCest.php b/tests/unit/Annotations/Annotation/GetNameTest.php similarity index 75% rename from tests/unit/Annotations/Annotation/GetNameCest.php rename to tests/unit/Annotations/Annotation/GetNameTest.php index b6ae8810b..c51e4b4dd 100644 --- a/tests/unit/Annotations/Annotation/GetNameCest.php +++ b/tests/unit/Annotations/Annotation/GetNameTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Annotation; use Phalcon\Annotations\Annotation; -use UnitTester; +use PHPUnit\Framework\TestCase; -class GetNameCest +final class GetNameTest extends TestCase { /** * Tests Phalcon\Annotations\Annotation :: getName() @@ -24,16 +24,14 @@ class GetNameCest * @author Jeremy PASTOURET * @since 2020-01-22 */ - public function annotationsAnnotationGetName(UnitTester $I) + public function testAnnotationsAnnotationGetName(): void { - $I->wantToTest('Annotations\Annotation - getName()'); - $name = 'NovAnnotation'; $annotation = new Annotation([ 'name' => 'NovAnnotation', ]); - $I->assertSame($annotation->getName(), $name); + $this->assertSame($annotation->getName(), $name); } } diff --git a/tests/unit/Annotations/Annotation/GetNamedArgumentCest.php b/tests/unit/Annotations/Annotation/GetNamedArgumentTest.php similarity index 88% rename from tests/unit/Annotations/Annotation/GetNamedArgumentCest.php rename to tests/unit/Annotations/Annotation/GetNamedArgumentTest.php index 3bbe31bce..141241428 100644 --- a/tests/unit/Annotations/Annotation/GetNamedArgumentCest.php +++ b/tests/unit/Annotations/Annotation/GetNamedArgumentTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Annotation; use Phalcon\Annotations\Annotation; -use UnitTester; +use PHPUnit\Framework\TestCase; -class GetNamedArgumentCest +final class GetNamedArgumentTest extends TestCase { private $PHANNOT_T_ARRAY = 308; private $PHANNOT_T_STRING = 303; @@ -27,10 +27,8 @@ class GetNamedArgumentCest * @author Jeremy PASTOURET * @since 2020-01-22 */ - public function annotationsAnnotationGetNamedArgument(UnitTester $I) + public function testAnnotationsAnnotationGetNamedArgument(): void { - $I->wantToTest('Annotations\Annotation - getNamedArgument()'); - $value = 'test'; $value1 = 'test1'; $value2 = 'test2'; @@ -96,12 +94,12 @@ public function annotationsAnnotationGetNamedArgument(UnitTester $I) $name1 => $value1, ]; - $I->assertSame($annotation->getNamedArgument($exprName), $result); + $this->assertSame($annotation->getNamedArgument($exprName), $result); $result1 = [ $name2 => $value2, ]; - $I->assertSame($annotation->getNamedArgument($exprName1), $result1); + $this->assertSame($annotation->getNamedArgument($exprName1), $result1); } } diff --git a/tests/unit/Annotations/Annotation/GetNamedParameterCest.php b/tests/unit/Annotations/Annotation/GetNamedParameterTest.php similarity index 87% rename from tests/unit/Annotations/Annotation/GetNamedParameterCest.php rename to tests/unit/Annotations/Annotation/GetNamedParameterTest.php index dff1544fd..338006998 100644 --- a/tests/unit/Annotations/Annotation/GetNamedParameterCest.php +++ b/tests/unit/Annotations/Annotation/GetNamedParameterTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Annotation; use Phalcon\Annotations\Annotation; -use UnitTester; +use PHPUnit\Framework\TestCase; -class GetNamedParameterCest +final class GetNamedParameterTest extends TestCase { private $PHANNOT_T_ARRAY = 308; private $PHANNOT_T_STRING = 303; @@ -27,10 +27,8 @@ class GetNamedParameterCest * @author Jeremy PASTOURET * @since 2020-01-22 */ - public function annotationsAnnotationGetNamedParameter(UnitTester $I) + public function testAnnotationsAnnotationGetNamedParameter(): void { - $I->wantToTest('Annotations\Annotation - getNamedParameter()'); - $value = 'test'; $value1 = 'test1'; $value2 = 'test2'; @@ -96,12 +94,12 @@ public function annotationsAnnotationGetNamedParameter(UnitTester $I) $name1 => $value1, ]; - $I->assertSame($annotation->getNamedParameter($exprName), $result); + $this->assertSame($annotation->getNamedParameter($exprName), $result); $result1 = [ $name2 => $value2, ]; - $I->assertSame($annotation->getNamedParameter($exprName1), $result1); + $this->assertSame($annotation->getNamedParameter($exprName1), $result1); } } diff --git a/tests/unit/Annotations/Annotation/HasArgumentCest.php b/tests/unit/Annotations/Annotation/HasArgumentTest.php similarity index 77% rename from tests/unit/Annotations/Annotation/HasArgumentCest.php rename to tests/unit/Annotations/Annotation/HasArgumentTest.php index 987a2ef6a..e11150b05 100644 --- a/tests/unit/Annotations/Annotation/HasArgumentCest.php +++ b/tests/unit/Annotations/Annotation/HasArgumentTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Annotation; use Phalcon\Annotations\Annotation; -use UnitTester; +use PHPUnit\Framework\TestCase; -class HasArgumentCest +final class HasArgumentTest extends TestCase { private $PHANNOT_T_STRING = 303; @@ -26,10 +26,8 @@ class HasArgumentCest * @author Jeremy PASTOURET * @since 2020-01-22 */ - public function annotationsAnnotationHasArgument(UnitTester $I) + public function testAnnotationsAnnotationHasArgument(): void { - $I->wantToTest('Annotations\Annotation - hasArgument()'); - $value = 'test'; $value1 = 'test1'; @@ -51,10 +49,8 @@ public function annotationsAnnotationHasArgument(UnitTester $I) ], ]); - $I->assertTrue($annotation->hasArgument(0)); - - $I->assertTrue($annotation->hasArgument(1)); - - $I->assertFalse($annotation->hasArgument(2)); + $this->assertTrue($annotation->hasArgument(0)); + $this->assertTrue($annotation->hasArgument(1)); + $this->assertFalse($annotation->hasArgument(2)); } } diff --git a/tests/unit/Annotations/Annotation/NumberArgumentsCest.php b/tests/unit/Annotations/Annotation/NumberArgumentsTest.php similarity index 82% rename from tests/unit/Annotations/Annotation/NumberArgumentsCest.php rename to tests/unit/Annotations/Annotation/NumberArgumentsTest.php index f0afc047f..bbac5cf7a 100644 --- a/tests/unit/Annotations/Annotation/NumberArgumentsCest.php +++ b/tests/unit/Annotations/Annotation/NumberArgumentsTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Annotation; use Phalcon\Annotations\Annotation; -use UnitTester; +use PHPUnit\Framework\TestCase; -class NumberArgumentsCest +final class NumberArgumentsTest extends TestCase { private $PHANNOT_T_STRING = 303; @@ -26,10 +26,8 @@ class NumberArgumentsCest * @author Jeremy PASTOURET * @since 2020-01-22 */ - public function annotationsAnnotationNumberArguments(UnitTester $I) + public function testAnnotationsAnnotationNumberArguments(): void { - $I->wantToTest('Annotations\Annotation - numberArguments()'); - $value = 'test'; $value1 = 'test1'; @@ -51,6 +49,6 @@ public function annotationsAnnotationNumberArguments(UnitTester $I) ], ]); - $I->assertSame($annotation->numberArguments(), 2); + $this->assertSame($annotation->numberArguments(), 2); } } diff --git a/tests/unit/Annotations/AnnotationsFactory/LoadCest.php b/tests/unit/Annotations/AnnotationsFactory/LoadTest.php similarity index 60% rename from tests/unit/Annotations/AnnotationsFactory/LoadCest.php rename to tests/unit/Annotations/AnnotationsFactory/LoadTest.php index 01dfa8a09..0ddda0211 100644 --- a/tests/unit/Annotations/AnnotationsFactory/LoadCest.php +++ b/tests/unit/Annotations/AnnotationsFactory/LoadTest.php @@ -13,16 +13,21 @@ namespace Phalcon\Tests\Unit\Annotations\AnnotationsFactory; +use Exception; use Phalcon\Annotations\Adapter\Apcu; use Phalcon\Annotations\AnnotationsFactory; -use Phalcon\Tests\Fixtures\Traits\FactoryTrait; -use UnitTester; +use Phalcon\Config\Config; +use Phalcon\Tests1\Fixtures\Traits\FactoryTrait2; +use PHPUnit\Framework\TestCase; -class LoadCest +final class LoadTest extends TestCase { - use FactoryTrait; + use FactoryTrait2; - public function _before(UnitTester $I) + /** + * @return void + */ + public function setUp(): void { $this->init(); } @@ -33,12 +38,10 @@ public function _before(UnitTester $I) * @author Phalcon Team * @since 2019-05-18 */ - public function imageAnnotationsFactoryLoad(UnitTester $I) + public function testAnnotationsFactoryLoad(): void { - $I->wantToTest('Annotations\AnnotationsFactory - load()'); - $options = $this->config->annotations; - $this->runTests($I, $options); + $this->runTests($options); } /** @@ -47,23 +50,23 @@ public function imageAnnotationsFactoryLoad(UnitTester $I) * @author Phalcon Team * @since 2019-05-18 */ - public function imageAnnotationsFactoryLoadArray(UnitTester $I) + public function testAnnotationsFactoryLoadArray(): void { - $I->wantToTest('Annotations\AnnotationsFactory - load()'); - $options = $this->arrayConfig['annotations']; - $this->runTests($I, $options); + $this->runTests($options); } - private function runTests(UnitTester $I, $options) + /** + * @param array $options + * + * @return void + * @throws Exception + */ + private function runTests(Config | array $options) { $factory = new AnnotationsFactory(); $adapter = $factory->load($options); - - $I->assertInstanceOf( - Apcu::class, - $adapter - ); + $this->assertInstanceOf(Apcu::class, $adapter); } } diff --git a/tests/unit/Annotations/AnnotationsFactory/NewInstanceCest.php b/tests/unit/Annotations/AnnotationsFactory/NewInstanceTest.php similarity index 50% rename from tests/unit/Annotations/AnnotationsFactory/NewInstanceCest.php rename to tests/unit/Annotations/AnnotationsFactory/NewInstanceTest.php index 2846d1bce..4c61c6f3f 100644 --- a/tests/unit/Annotations/AnnotationsFactory/NewInstanceCest.php +++ b/tests/unit/Annotations/AnnotationsFactory/NewInstanceTest.php @@ -13,39 +13,19 @@ namespace Phalcon\Tests\Unit\Annotations\AnnotationsFactory; -use Codeception\Example; use Phalcon\Annotations\Adapter\Apcu; use Phalcon\Annotations\Adapter\Memory; use Phalcon\Annotations\Adapter\Stream; use Phalcon\Annotations\AnnotationsFactory; -use UnitTester; +use Phalcon\Annotations\Exception; +use PHPUnit\Framework\TestCase; -class NewInstanceCest +final class NewInstanceTest extends TestCase { /** - * Tests Phalcon\Annotations\AdapterFactory :: newInstance() - * - * @dataProvider getExamples - * - * @author Phalcon Team - * @since 2019-05-19 + * @return array[] */ - public function annotationsAdapterFactoryNewInstance(UnitTester $I, Example $example) - { - $I->wantToTest('Annotations\AdapterFactory - newInstance() - ' . $example[0]); - - $factory = new AnnotationsFactory(); - $name = 'apcu'; - - $image = $factory->newInstance($example[0]); - - $I->assertInstanceOf( - $example[1], - $image - ); - } - - private function getExamples(): array + public static function providerExamples(): array { return [ [ @@ -62,4 +42,40 @@ private function getExamples(): array ], ]; } + + /** + * Tests Phalcon\Annotations\AdapterFactory :: newInstance() + * + * @dataProvider providerExamples + * + * @author Phalcon Team + * @since 2019-05-19 + */ + public function testAnnotationsAdapterFactoryNewInstance( + string $name, + string $class + ): void { + $factory = new AnnotationsFactory(); + $image = $factory->newInstance($name); + + $this->assertInstanceOf($class, $image); + } + + /** + * Tests Phalcon\Annotations\AdapterFactory :: newInstance() - exception + * + * @return void + * + * @author Phalcon Team + * @since 2022-08-02 + */ + public function testAnnotationsAdapterFactoryNewInstanceException(): void + { + $name = uniqid('service-'); + $this->expectException(Exception::class); + $this->expectExceptionMessage('Service ' . $name . ' is not registered'); + + $factory = new AnnotationsFactory(); + $factory->newInstance($name); + } } diff --git a/tests/unit/Annotations/Collection/ConstructCest.php b/tests/unit/Annotations/Collection/ConstructTest.php similarity index 71% rename from tests/unit/Annotations/Collection/ConstructCest.php rename to tests/unit/Annotations/Collection/ConstructTest.php index b49caf9d6..db61b8832 100644 --- a/tests/unit/Annotations/Collection/ConstructCest.php +++ b/tests/unit/Annotations/Collection/ConstructTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Collection; use Phalcon\Annotations\Collection; -use UnitTester; +use PHPUnit\Framework\TestCase; -class ConstructCest +final class ConstructTest extends TestCase { /** * Tests Phalcon\Annotations\Collection :: __construct() @@ -24,15 +24,13 @@ class ConstructCest * @author Jeremy PASTOURET * @since 2020-01-27 */ - public function annotationsCollectionConstruct(UnitTester $I) + public function testAnnotationsCollectionConstruct(): void { - $I->wantToTest('Annotations\Collection - __construct()'); - $collection = new Collection(); $expected = Collection::class; $actual = $collection; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); } /** @@ -42,10 +40,8 @@ public function annotationsCollectionConstruct(UnitTester $I) * @author Jeremy PASTOURET * @since 2020-01-27 */ - public function annotationsCollectionConstructWithArrayParam(UnitTester $I) + public function testAnnotationsCollectionConstructWithArrayParam(): void { - $I->wantToTest('Annotations\Collection - __construct() with array parameter'); - $collection = new Collection( [ [ @@ -56,6 +52,6 @@ public function annotationsCollectionConstructWithArrayParam(UnitTester $I) $expected = Collection::class; $actual = $collection; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); } } diff --git a/tests/unit/Annotations/Collection/CountCest.php b/tests/unit/Annotations/Collection/CountTest.php similarity index 81% rename from tests/unit/Annotations/Collection/CountCest.php rename to tests/unit/Annotations/Collection/CountTest.php index 6be32b373..739f5c1ae 100644 --- a/tests/unit/Annotations/Collection/CountCest.php +++ b/tests/unit/Annotations/Collection/CountTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Collection; use Phalcon\Annotations\Collection; -use UnitTester; +use PHPUnit\Framework\TestCase; -class CountCest +final class CountTest extends TestCase { /** * Tests Phalcon\Annotations\Collection :: count() @@ -24,10 +24,8 @@ class CountCest * @author Jeremy PASTOURET * @since 2020-01-27 */ - public function annotationsCollectionCount(UnitTester $I) + public function testAnnotationsCollectionCount(): void { - $I->wantToTest('Annotations\Collection - count()'); - $reflectionData = [ [ 'name' => 'NovAnnotation', @@ -41,6 +39,6 @@ public function annotationsCollectionCount(UnitTester $I) $expected = count($reflectionData); $actual = $collection->count(); - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); } } diff --git a/tests/unit/Annotations/Collection/CurrentCest.php b/tests/unit/Annotations/Collection/CurrentTest.php similarity index 73% rename from tests/unit/Annotations/Collection/CurrentCest.php rename to tests/unit/Annotations/Collection/CurrentTest.php index 93ba5da3e..d266b6ad8 100644 --- a/tests/unit/Annotations/Collection/CurrentCest.php +++ b/tests/unit/Annotations/Collection/CurrentTest.php @@ -15,9 +15,9 @@ use Phalcon\Annotations\Annotation; use Phalcon\Annotations\Collection; -use UnitTester; +use PHPUnit\Framework\TestCase; -class CurrentCest +final class CurrentTest extends TestCase { /** * Tests Phalcon\Annotations\Collection :: current() @@ -25,13 +25,11 @@ class CurrentCest * @author Jeremy PASTOURET * @since 2020-01-27 */ - public function annotationsCollectionCurrent(UnitTester $I) + public function testAnnotationsCollectionCurrent(): void { - $I->wantToTest('Annotations\Collection - current()'); - $collection = new Collection(); - $I->assertFalse($collection->current()); + $this->assertFalse($collection->current()); } /** @@ -40,10 +38,8 @@ public function annotationsCollectionCurrent(UnitTester $I) * @author Jeremy PASTOURET * @since 2020-01-27 */ - public function annotationsCollectionCurrentWithAnnotations(UnitTester $I) + public function testAnnotationsCollectionCurrentWithAnnotations(): void { - $I->wantToTest('Annotations\Collection - current() with annotations'); - $dataAnnotation = [ 'name' => 'NovAnnotation', ]; @@ -60,6 +56,6 @@ public function annotationsCollectionCurrentWithAnnotations(UnitTester $I) $collection = new Collection($reflectionData); $annotation = new Annotation($dataAnnotation); - $I->assertEquals($annotation, $collection->current()); + $this->assertEquals($annotation, $collection->current()); } } diff --git a/tests/unit/Annotations/Collection/GetAllCest.php b/tests/unit/Annotations/Collection/GetAllTest.php similarity index 86% rename from tests/unit/Annotations/Collection/GetAllCest.php rename to tests/unit/Annotations/Collection/GetAllTest.php index 3abf87611..bf112e5aa 100644 --- a/tests/unit/Annotations/Collection/GetAllCest.php +++ b/tests/unit/Annotations/Collection/GetAllTest.php @@ -15,9 +15,9 @@ use Phalcon\Annotations\Annotation; use Phalcon\Annotations\Collection; -use UnitTester; +use PHPUnit\Framework\TestCase; -class GetAllCest +final class GetAllTest extends TestCase { /** * Tests Phalcon\Annotations\Collection :: getAll() @@ -25,10 +25,8 @@ class GetAllCest * @author Jeremy PASTOURET * @since 2020-01-27 */ - public function annotationsCollectionGetAll(UnitTester $I) + public function testAnnotationsCollectionGetAll(): void { - $I->wantToTest('Annotations\Collection - getAll()'); - $dataAnnotation = [ 'name' => 'NovAnnotation', ]; @@ -59,11 +57,11 @@ public function annotationsCollectionGetAll(UnitTester $I) // Check the result if the annotation doesn't exist $actual = $collection->getAll('Phalconatation'); - $I->assertEmpty($actual); + $this->assertEmpty($actual); // Need to find two annotations with the name NovAnnotation $expected = $resultAnnotation; $actual = $collection->getAll('NovAnnotation'); - $I->assertEquals($expected, $actual); + $this->assertEquals($expected, $actual); } } diff --git a/tests/unit/Annotations/Collection/GetAnnotationsCest.php b/tests/unit/Annotations/Collection/GetAnnotationsTest.php similarity index 86% rename from tests/unit/Annotations/Collection/GetAnnotationsCest.php rename to tests/unit/Annotations/Collection/GetAnnotationsTest.php index 2270cc10e..8f2358bfc 100644 --- a/tests/unit/Annotations/Collection/GetAnnotationsCest.php +++ b/tests/unit/Annotations/Collection/GetAnnotationsTest.php @@ -15,9 +15,9 @@ use Phalcon\Annotations\Annotation; use Phalcon\Annotations\Collection; -use UnitTester; +use PHPUnit\Framework\TestCase; -class GetAnnotationsCest +final class GetAnnotationsTest extends TestCase { /** * Tests Phalcon\Annotations\Collection :: getAnnotations() @@ -25,10 +25,8 @@ class GetAnnotationsCest * @author Jeremy PASTOURET * @since 2020-01-27 */ - public function annotationsCollectionGetAnnotations(UnitTester $I) + public function testAnnotationsCollectionGetAnnotations(): void { - $I->wantToTest('Annotations\Collection - getAnnotations()'); - $dataAnnotation = [ 'name' => 'NovAnnotation', ]; @@ -62,6 +60,6 @@ public function annotationsCollectionGetAnnotations(UnitTester $I) // Need to find two annotations with the name NovAnnotation $expected = $resultAnnotation; $actual = $collection->getAnnotations(); - $I->assertEquals($expected, $actual); + $this->assertEquals($expected, $actual); } } diff --git a/tests/unit/Annotations/Collection/GetCest.php b/tests/unit/Annotations/Collection/GetTest.php similarity index 72% rename from tests/unit/Annotations/Collection/GetCest.php rename to tests/unit/Annotations/Collection/GetTest.php index f1f98b4d3..9c932dd32 100644 --- a/tests/unit/Annotations/Collection/GetCest.php +++ b/tests/unit/Annotations/Collection/GetTest.php @@ -16,9 +16,9 @@ use Phalcon\Annotations\Annotation; use Phalcon\Annotations\Collection; use Phalcon\Annotations\Exception; -use UnitTester; +use PHPUnit\Framework\TestCase; -class GetCest +final class GetTest extends TestCase { /** * Tests Phalcon\Annotations\Collection :: get() @@ -26,10 +26,8 @@ class GetCest * @author Jeremy PASTOURET * @since 2020-01-27 */ - public function annotationsCollectionGet(UnitTester $I) + public function testAnnotationsCollectionGet(): void { - $I->wantToTest('Annotations\Collection - get()'); - $dataAnnotation = [ 'name' => 'NovAnnotation', ]; @@ -48,15 +46,15 @@ public function annotationsCollectionGet(UnitTester $I) $expected = $annotation; $actual = $collection->get('Phalconatation'); - $I->assertEquals($expected, $actual); + $this->assertEquals($expected, $actual); //Check what happens if collection doesn't find an annotation - $I->expectThrowable( - new Exception("Collection does not have an annotation called 'NoExist'"), - function () { - $collection = new Collection(); - $collection->get('NoExist'); - } + $this->expectException(Exception::class); + $this->expectExceptionMessage( + "Collection does not have an annotation called 'NoExist'" ); + + $collection = new Collection(); + $collection->get('NoExist'); } } diff --git a/tests/unit/Annotations/Collection/HasCest.php b/tests/unit/Annotations/Collection/HasTest.php similarity index 81% rename from tests/unit/Annotations/Collection/HasCest.php rename to tests/unit/Annotations/Collection/HasTest.php index 7f6a97d56..e0d04ae98 100644 --- a/tests/unit/Annotations/Collection/HasCest.php +++ b/tests/unit/Annotations/Collection/HasTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Collection; use Phalcon\Annotations\Collection; -use UnitTester; +use PHPUnit\Framework\TestCase; -class HasCest +final class HasTest extends TestCase { /** * Tests Phalcon\Annotations\Collection :: has() @@ -24,10 +24,8 @@ class HasCest * @author Jeremy PASTOURET * @since 2020-01-31 */ - public function annotationsCollectionHas(UnitTester $I) + public function testAnnotationsCollectionHas(): void { - $I->wantToTest('Annotations\Collection - has()'); - $dataAnnotation = [ 'name' => 'NovAnnotation', ]; @@ -44,9 +42,9 @@ public function annotationsCollectionHas(UnitTester $I) $collection = new Collection($reflectionData); $actual = $collection->has('Phalconatation'); - $I->assertTrue($actual); + $this->assertTrue($actual); $actual = $collection->has('Phalcony'); - $I->assertFalse($actual); + $this->assertFalse($actual); } } diff --git a/tests/unit/Annotations/Collection/KeyNextRewindCest.php b/tests/unit/Annotations/Collection/KeyNextRewindTest.php similarity index 76% rename from tests/unit/Annotations/Collection/KeyNextRewindCest.php rename to tests/unit/Annotations/Collection/KeyNextRewindTest.php index 6c286a852..55f8e6734 100644 --- a/tests/unit/Annotations/Collection/KeyNextRewindCest.php +++ b/tests/unit/Annotations/Collection/KeyNextRewindTest.php @@ -15,9 +15,9 @@ use Phalcon\Annotations\Annotation; use Phalcon\Annotations\Collection; -use UnitTester; +use PHPUnit\Framework\TestCase; -class KeyNextRewindCest +final class KeyNextRewindTest extends TestCase { /** * Tests Phalcon\Annotations\Collection :: key() / next() / rewind() @@ -25,10 +25,8 @@ class KeyNextRewindCest * @author Jeremy PASTOURET * @since 2020-01-31 */ - public function annotationsCollectionKeyNextRewind(UnitTester $I) + public function testAnnotationsCollectionKeyNextRewind(): void { - $I->wantToTest('Annotations\Collection - key() / next() / rewind()'); - $dataAnnotation = [ 'name' => 'NovAnnotation', ]; @@ -48,30 +46,30 @@ public function annotationsCollectionKeyNextRewind(UnitTester $I) $expected = 0; $actual = $collection->key(); - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = $annotation; $actual = $collection->current(); - $I->assertEquals($expected, $actual); + $this->assertEquals($expected, $actual); $collection->next(); $expected = 1; $actual = $collection->key(); - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = $annotation1; $actual = $collection->current(); - $I->assertEquals($expected, $actual); + $this->assertEquals($expected, $actual); $collection->rewind(); $expected = 0; $actual = $collection->key(); - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = $annotation; $actual = $collection->current(); - $I->assertEquals($expected, $actual); + $this->assertEquals($expected, $actual); } } diff --git a/tests/unit/Annotations/Collection/ValidCest.php b/tests/unit/Annotations/Collection/ValidTest.php similarity index 80% rename from tests/unit/Annotations/Collection/ValidCest.php rename to tests/unit/Annotations/Collection/ValidTest.php index 9995a31e5..119037c0c 100644 --- a/tests/unit/Annotations/Collection/ValidCest.php +++ b/tests/unit/Annotations/Collection/ValidTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Collection; use Phalcon\Annotations\Collection; -use UnitTester; +use PHPUnit\Framework\TestCase; -class ValidCest +final class ValidTest extends TestCase { /** * Tests Phalcon\Annotations\Collection :: valid() @@ -24,10 +24,8 @@ class ValidCest * @author Jeremy PASTOURET * @since 2020-01-31 */ - public function annotationsCollectionValid(UnitTester $I) + public function testAnnotationsCollectionValid(): void { - $I->wantToTest('Annotations\Collection - valid()'); - $dataAnnotation = [ 'name' => 'NovAnnotation', ]; @@ -44,16 +42,16 @@ public function annotationsCollectionValid(UnitTester $I) $collection = new Collection($reflectionData); $actual = $collection->valid(); - $I->assertTrue($actual); + $this->assertTrue($actual); $collection->next(); $actual = $collection->valid(); - $I->assertTrue($actual); + $this->assertTrue($actual); $collection->next(); $actual = $collection->valid(); - $I->assertFalse($actual); + $this->assertFalse($actual); } } diff --git a/tests/unit/Annotations/Reader/ParseDocBlockCest.php b/tests/unit/Annotations/Reader/ParseDocBlockTest.php similarity index 88% rename from tests/unit/Annotations/Reader/ParseDocBlockCest.php rename to tests/unit/Annotations/Reader/ParseDocBlockTest.php index 953b7b6f6..946c0f936 100644 --- a/tests/unit/Annotations/Reader/ParseDocBlockCest.php +++ b/tests/unit/Annotations/Reader/ParseDocBlockTest.php @@ -14,11 +14,11 @@ namespace Phalcon\Tests\Unit\Annotations\Reader; use Phalcon\Annotations\Reader; -use UnitTester; +use PHPUnit\Framework\TestCase; use function ksort; -class ParseDocBlockCest +final class ParseDocBlockTest extends TestCase { /** * Tests Phalcon\Annotations\Reader :: parseDocBlock() @@ -26,10 +26,8 @@ class ParseDocBlockCest * @author Phalcon Team * @since 2020-02-21 */ - public function annotationsReaderParseDocBlock(UnitTester $I) + public function testAnnotationsReaderParseDocBlock(): void { - $I->wantToTest('Annotations\Reader - parseDocBlock()'); - $docBlock = <<parseDocBlock($docBlock); - $I->assertIsArray($parsed); + $this->assertIsArray($parsed); $expected = 4; $actual = $parsed; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $expected = [ 'file' => 'eval code', @@ -58,7 +56,7 @@ public function annotationsReaderParseDocBlock(UnitTester $I) ]; ksort($parsed[0]); $actual = $parsed[0]; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = [ 'file' => 'eval code', @@ -68,7 +66,7 @@ public function annotationsReaderParseDocBlock(UnitTester $I) ]; ksort($parsed[1]); $actual = $parsed[1]; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = [ 'arguments' => [ @@ -86,7 +84,7 @@ public function annotationsReaderParseDocBlock(UnitTester $I) ]; ksort($parsed[2]); $actual = $parsed[2]; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = [ 'arguments' => [ @@ -143,6 +141,6 @@ public function annotationsReaderParseDocBlock(UnitTester $I) ]; ksort($parsed[3]); $actual = $parsed[3]; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); } } diff --git a/tests/unit/Annotations/Reader/ParseCest.php b/tests/unit/Annotations/Reader/ParseTest.php similarity index 67% rename from tests/unit/Annotations/Reader/ParseCest.php rename to tests/unit/Annotations/Reader/ParseTest.php index 247749ba8..817865223 100644 --- a/tests/unit/Annotations/Reader/ParseCest.php +++ b/tests/unit/Annotations/Reader/ParseTest.php @@ -15,40 +15,16 @@ use Phalcon\Annotations\Exception; use Phalcon\Annotations\Reader; +use PHPUnit\Framework\TestCase; use ReflectionException; -use UnitTester; -use function dataDir; +use function dataDir2; use function str_replace; use const DIRECTORY_SEPARATOR; -class ParseCest +final class ParseTest extends TestCase { - /** - * Test throws ReflectionException when non-existent got class - * - * @author Phalcon Team - * @since 2016-01-25 - */ - public function testParseWithNonExistentClass(UnitTester $I) - { - if (version_compare(PHP_VERSION, '8.0.0', '>=')) { - $message = 'Class "TestClass1" does not exist'; - } else { - $message = 'Class TestClass1 does not exist'; - } - - $I->expectThrowable( - new ReflectionException($message, -1), - function () { - $reader = new Reader(); - - $reader->parse('TestClass1'); - } - ); - } - /** * Test throws Phalcon\Annotations\Exception when got class with invalid * annotation @@ -56,31 +32,44 @@ function () { * @author Phalcon Team * @since 2016-01-25 */ - public function testParseWithInvalidAnnotation(UnitTester $I) + public function testParseWithInvalidAnnotation(): void { $filename = 'fixtures' . DIRECTORY_SEPARATOR . 'Annotations' . DIRECTORY_SEPARATOR . 'TestInvalid.php'; - $includeFile = str_replace("/", DIRECTORY_SEPARATOR, dataDir($filename)); + $includeFile = str_replace("/", DIRECTORY_SEPARATOR, dataDir2($filename)); - $I->seeFileFound($includeFile); + $this->assertFileExists($includeFile); require_once $includeFile; - $file = dataDir($filename); + $file = dataDir2($filename); //directory based on DIRECTORY_SEPARATOR $file = str_replace("/", DIRECTORY_SEPARATOR, $file); - $I->expectThrowable( - new Exception('Syntax error, unexpected EOF in ' . $file), - function () { - $reader = new Reader(); + $this->expectException(Exception::class); + $this->expectExceptionMessage('Syntax error, unexpected EOF in ' . $file); + + $reader = new Reader(); - $reader->parse('TestInvalid'); - } - ); + $reader->parse('TestInvalid'); } + /** + * Test throws ReflectionException when non-existent got class + * + * @author Phalcon Team + * @since 2016-01-25 + */ + public function testParseWithNonExistentClass(): void + { + $this->expectException(ReflectionException::class); + $this->expectExceptionMessage('Class "TestClass1" does not exist'); + + $reader = new Reader(); + + $reader->parse('TestClass1'); + } /** * Tests Reader::parse @@ -88,11 +77,11 @@ function () { * @author Phalcon Team * @since 2016-01-25 */ - public function testReaderParse(UnitTester $I) + public function testReaderParse(): void { - $includeFile = dataDir('fixtures/Annotations/TestClass.php'); + $includeFile = dataDir2('fixtures/Annotations/TestClass.php'); - $I->seeFileFound($includeFile); + $this->assertFileExists($includeFile); require_once $includeFile; @@ -100,490 +89,490 @@ public function testReaderParse(UnitTester $I) $parsing = $reader->parse('TestClass'); $actual = isset($parsing['class']); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = 9; $actual = $parsing['class']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); // Simple $expected = 'Simple'; $actual = $parsing['class'][0]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $actual = isset($parsing['class'][0]['arguments']); - $I->assertFalse($actual); + $this->assertFalse($actual); // Single Param $expected = 'SingleParam'; $actual = $parsing['class'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $actual = isset($parsing['class'][1]['arguments']); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = 1; $actual = $parsing['class'][1]['arguments']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $expected = 'Param'; $actual = $parsing['class'][1]['arguments'][0]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Multiple Params $expected = 8; $actual = $parsing['class'][2]['arguments']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $actual = isset($parsing['class'][2]['arguments']); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = 'MultipleParams'; $actual = $parsing['class'][2]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'First'; $actual = $parsing['class'][2]['arguments'][0]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'Second'; $actual = $parsing['class'][2]['arguments'][1]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = '1'; $actual = $parsing['class'][2]['arguments'][2]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = '1.1'; $actual = $parsing['class'][2]['arguments'][3]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = '-10'; $actual = $parsing['class'][2]['arguments'][4]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 305; $actual = $parsing['class'][2]['arguments'][5]['expr']['type']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 306; $actual = $parsing['class'][2]['arguments'][6]['expr']['type']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 304; $actual = $parsing['class'][2]['arguments'][7]['expr']['type']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Single Array Param $expected = 1; $actual = $parsing['class'][3]['arguments']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $expected = 3; $actual = $parsing['class'][3]['arguments'][0]['expr']['items']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $actual = isset($parsing['class'][3]['arguments']); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = 'Params'; $actual = $parsing['class'][3]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 308; $actual = $parsing['class'][3]['arguments'][0]['expr']['type']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'key1'; $actual = $parsing['class'][3]['arguments'][0]['expr']['items'][0]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'key2'; $actual = $parsing['class'][3]['arguments'][0]['expr']['items'][1]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'key3'; $actual = $parsing['class'][3]['arguments'][0]['expr']['items'][2]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Hash Params $expected = 1; $actual = $parsing['class'][8]['arguments']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $expected = 3; $actual = $parsing['class'][4]['arguments'][0]['expr']['items']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $actual = isset($parsing['class'][4]['arguments']); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = 'HashParams'; $actual = $parsing['class'][4]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 308; $actual = $parsing['class'][4]['arguments'][0]['expr']['type']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'key1'; $actual = $parsing['class'][4]['arguments'][0]['expr']['items'][0]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'value'; $actual = $parsing['class'][4]['arguments'][0]['expr']['items'][0]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'key2'; $actual = $parsing['class'][4]['arguments'][0]['expr']['items'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'value'; $actual = $parsing['class'][4]['arguments'][0]['expr']['items'][1]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'key3'; $actual = $parsing['class'][4]['arguments'][0]['expr']['items'][2]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'value'; $actual = $parsing['class'][4]['arguments'][0]['expr']['items'][2]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Named Params $expected = 2; $actual = $parsing['class'][5]['arguments']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $actual = isset($parsing['class'][5]['arguments']); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = 'NamedParams'; $actual = $parsing['class'][5]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'second'; $actual = $parsing['class'][5]['arguments'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'other'; $actual = $parsing['class'][5]['arguments'][1]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'second'; $actual = $parsing['class'][5]['arguments'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'other'; $actual = $parsing['class'][5]['arguments'][1]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Alternative Named Params $expected = 2; $actual = $parsing['class'][6]['arguments']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $actual = isset($parsing['class'][6]['arguments']); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = 'AlternativeNamedParams'; $actual = $parsing['class'][6]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'second'; $actual = $parsing['class'][6]['arguments'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'other'; $actual = $parsing['class'][6]['arguments'][1]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'second'; $actual = $parsing['class'][6]['arguments'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'other'; $actual = $parsing['class'][6]['arguments'][1]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Alternative Hash Params $expected = 1; $actual = $parsing['class'][7]['arguments']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $expected = 3; $actual = $parsing['class'][7]['arguments'][0]['expr']['items']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $actual = isset($parsing['class'][7]['arguments']); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = 'AlternativeHashParams'; $actual = $parsing['class'][7]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 308; $actual = $parsing['class'][7]['arguments'][0]['expr']['type']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'key1'; $actual = $parsing['class'][7]['arguments'][0]['expr']['items'][0]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'value'; $actual = $parsing['class'][7]['arguments'][0]['expr']['items'][0]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'key2'; $actual = $parsing['class'][7]['arguments'][0]['expr']['items'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'value'; $actual = $parsing['class'][7]['arguments'][0]['expr']['items'][1]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'key3'; $actual = $parsing['class'][7]['arguments'][0]['expr']['items'][2]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'value'; $actual = $parsing['class'][7]['arguments'][0]['expr']['items'][2]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Recursive Hash $expected = 1; $actual = $parsing['class'][8]['arguments']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $expected = 3; $actual = $parsing['class'][8]['arguments'][0]['expr']['items']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $actual = isset($parsing['class'][8]['arguments']); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = 'RecursiveHash'; $actual = $parsing['class'][8]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 308; $actual = $parsing['class'][8]['arguments'][0]['expr']['type']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'key1'; $actual = $parsing['class'][8]['arguments'][0]['expr']['items'][0]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'value'; $actual = $parsing['class'][8]['arguments'][0]['expr']['items'][0]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'key2'; $actual = $parsing['class'][8]['arguments'][0]['expr']['items'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'value'; $actual = $parsing['class'][8]['arguments'][0]['expr']['items'][1]['expr']['value']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'key3'; $actual = $parsing['class'][8]['arguments'][0]['expr']['items'][2]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 308; $actual = $parsing['class'][8]['arguments'][0]['expr']['items'][2]['expr']['type']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Constants $expected = 1; $actual = $parsing['constants']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $actual = isset($parsing['constants']); - $I->assertTrue($actual); + $this->assertTrue($actual); $actual = isset($parsing['constants']['TEST_CONST2']); - $I->assertFalse($actual); + $this->assertFalse($actual); $expected = 'Simple'; $actual = $parsing['constants']['TEST_CONST1'][0]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Properties $expected = 3; $actual = $parsing['properties']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $actual = isset($parsing['properties']); - $I->assertTrue($actual); + $this->assertTrue($actual); // Multiple well-ordered annotations $expected = 4; $actual = $parsing['properties']['testProp1']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $actual = isset($parsing['properties']['testProp1']); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = 'var'; $actual = $parsing['properties']['testProp1'][0]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'Simple'; $actual = $parsing['properties']['testProp1'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'SingleParam'; $actual = $parsing['properties']['testProp1'][2]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'MultipleParams'; $actual = $parsing['properties']['testProp1'][3]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Comment without content $actual = isset($parsing['properties']['testProp2']); - $I->assertFalse($actual); + $this->assertFalse($actual); // Same line annotations $expected = 3; $actual = $parsing['properties']['testProp3']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $expected = 'Simple'; $actual = $parsing['properties']['testProp3'][0]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'SingleParam'; $actual = $parsing['properties']['testProp3'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'MultipleParams'; $actual = $parsing['properties']['testProp3'][2]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Same line annotations $expected = 3; $actual = $parsing['properties']['testProp4']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $expected = 'Simple'; $actual = $parsing['properties']['testProp4'][0]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'SingleParam'; $actual = $parsing['properties']['testProp4'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'MultipleParams'; $actual = $parsing['properties']['testProp4'][2]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // No docblock $actual = isset($parsing['properties']['testMethod5']); - $I->assertFalse($actual); + $this->assertFalse($actual); // No annotations $actual = isset($parsing['properties']['testMethod6']); - $I->assertFalse($actual); + $this->assertFalse($actual); // Properties $expected = 4; $actual = $parsing['methods']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $actual = isset($parsing['methods']); - $I->assertTrue($actual); + $this->assertTrue($actual); // Multiple well-ordered annotations $expected = 5; $actual = $parsing['methods']['testMethod1']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $actual = isset($parsing['methods']['testMethod1']); - $I->assertTrue($actual); + $this->assertTrue($actual); $expected = 'return'; $actual = $parsing['methods']['testMethod1'][0]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'Simple'; $actual = $parsing['methods']['testMethod1'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'SingleParam'; $actual = $parsing['methods']['testMethod1'][2]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'MultipleParams'; $actual = $parsing['methods']['testMethod1'][3]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'NamedMultipleParams'; $actual = $parsing['methods']['testMethod1'][4]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Comment without content $actual = isset($parsing['methods']['testMethod2']); - $I->assertFalse($actual); + $this->assertFalse($actual); // Same line annotations $expected = 3; $actual = $parsing['methods']['testMethod3']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $expected = 'Simple'; $actual = $parsing['methods']['testMethod3'][0]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'SingleParam'; $actual = $parsing['methods']['testMethod3'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'MultipleParams'; $actual = $parsing['methods']['testMethod3'][2]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Unordered annotations $expected = 3; $actual = $parsing['methods']['testMethod4']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $expected = 'Simple'; $actual = $parsing['methods']['testMethod4'][0]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'SingleParam'; $actual = $parsing['methods']['testMethod4'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'MultipleParams'; $actual = $parsing['methods']['testMethod4'][2]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); // Unordered annotations + extra content $expected = 3; $actual = $parsing['methods']['testMethod5']; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); $expected = 'Simple'; $actual = $parsing['methods']['testMethod5'][0]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'SingleParam'; $actual = $parsing['methods']['testMethod5'][1]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 'MultipleParams'; $actual = $parsing['methods']['testMethod5'][2]['name']; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); } } diff --git a/tests/unit/Annotations/Reflection/ConstructCest.php b/tests/unit/Annotations/Reflection/ConstructTest.php similarity index 66% rename from tests/unit/Annotations/Reflection/ConstructCest.php rename to tests/unit/Annotations/Reflection/ConstructTest.php index 139e39da6..d53e6cab4 100644 --- a/tests/unit/Annotations/Reflection/ConstructCest.php +++ b/tests/unit/Annotations/Reflection/ConstructTest.php @@ -17,46 +17,32 @@ use Phalcon\Annotations\Collection; use Phalcon\Annotations\Reader; use Phalcon\Annotations\Reflection; -use UnitTester; +use PHPUnit\Framework\TestCase; -use function dataDir; +use function dataDir2; -class ConstructCest +final class ConstructTest extends TestCase { - /** - * Executed before each test. - * - * @param UnitTester $I - */ - protected function _before(UnitTester $I) - { - require_once dataDir('fixtures/Annotations/TestClass.php'); - } - /** * Tests Phalcon\Annotations\Reflection :: __construct() * * @author Phalcon Team * @since 2020-02-21 */ - public function annotationsReflectionConstruct(UnitTester $I) + public function testAnnotationsReflectionConstruct(): void { - $I->wantToTest('Annotations\Reflection - __construct()'); - $reflection = new Reflection(); - $I->assertInstanceOf(Reflection::class, $reflection); + $this->assertInstanceOf(Reflection::class, $reflection); } /** * Tests parsing class annotations * - * @param UnitTester $I - * * @author Phalcon Team * @since 2016-01-26 */ - public function testClassAnnotations(UnitTester $I) + public function testClassAnnotations(): void { $reader = new Reader(); @@ -65,126 +51,136 @@ public function testClassAnnotations(UnitTester $I) ); $constantsAnnotations = $reflection->getConstantsAnnotations(); - $I->assertIsArray($constantsAnnotations); + $this->assertIsArray($constantsAnnotations); $annotations = $constantsAnnotations['TEST_CONST1']; $expected = Collection::class; $actual = $annotations; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $actual = $annotations->has('Simple'); - $I->assertTrue($actual); + $this->assertTrue($actual); $methodsAnnotations = $reflection->getMethodsAnnotations(); - $I->assertIsArray($methodsAnnotations); + $this->assertIsArray($methodsAnnotations); $expected = Collection::class; $actual = $methodsAnnotations['testMethod1']; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $total = 0; foreach ($methodsAnnotations as $method => $annotations) { - $I->assertIsString($method); + $this->assertIsString($method); $number = 0; foreach ($annotations as $annotation) { $expected = Annotation::class; $actual = $annotation; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $number++; $total++; } - $I->assertGreaterThan(0, $number); + $this->assertGreaterThan(0, $number); } $expected = 14; $actual = $total; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); /** @var Collection $annotations */ $annotations = $methodsAnnotations['testMethod1']; $actual = $annotations->has('Simple'); - $I->assertTrue($actual); + $this->assertTrue($actual); $actual = $annotations->has('NoSimple'); - $I->assertFalse($actual); + $this->assertFalse($actual); $annotation = $annotations->get('Simple'); $expected = 'Simple'; $actual = $annotation->getName(); - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = []; $actual = $annotation->getArguments(); - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 0; $actual = $annotation->numberArguments(); - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $actual = $annotation->hasArgument('none'); - $I->assertFalse($actual); + $this->assertFalse($actual); $annotation = $annotations->get('NamedMultipleParams'); $expected = 'NamedMultipleParams'; $actual = $annotation->getName(); - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 2; $actual = $annotation->numberArguments(); - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = ['first' => 'First', 'second' => 'Second']; $actual = $annotation->getArguments(); - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $actual = $annotation->hasArgument('first'); - $I->assertTrue($actual); + $this->assertTrue($actual); - $I->assertSame('First', $annotation->getArgument('first')); + $this->assertSame('First', $annotation->getArgument('first')); $actual = $annotation->hasArgument('none'); - $I->assertFalse($actual); + $this->assertFalse($actual); $propertiesAnnotations = $reflection->getPropertiesAnnotations(); - $I->assertIsArray($propertiesAnnotations); + $this->assertIsArray($propertiesAnnotations); $expected = Collection::class; $actual = $propertiesAnnotations['testProp1']; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $total = 0; foreach ($propertiesAnnotations as $annotations) { $expected = Collection::class; $actual = $propertiesAnnotations['testProp1']; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $number = 0; foreach ($annotations as $annotation) { $expected = Annotation::class; $actual = $annotation; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $number++; $total++; } - $I->assertGreaterThan(0, $number); + $this->assertGreaterThan(0, $number); } $expected = 10; $actual = $total; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); + } + + /** + * Executed before each test. + * + * @param + */ + protected function setUp(): void + { + require_once dataDir2('fixtures/Annotations/TestClass.php'); } } diff --git a/tests/unit/Annotations/Reflection/GetClassAnnotationsCest.php b/tests/unit/Annotations/Reflection/GetClassAnnotationsTest.php similarity index 72% rename from tests/unit/Annotations/Reflection/GetClassAnnotationsCest.php rename to tests/unit/Annotations/Reflection/GetClassAnnotationsTest.php index 69f6b0b15..6af9e288e 100644 --- a/tests/unit/Annotations/Reflection/GetClassAnnotationsCest.php +++ b/tests/unit/Annotations/Reflection/GetClassAnnotationsTest.php @@ -17,30 +17,24 @@ use Phalcon\Annotations\Collection; use Phalcon\Annotations\Reader; use Phalcon\Annotations\Reflection; -use UnitTester; +use PHPUnit\Framework\TestCase; -class GetClassAnnotationsCest -{ - /** - * executed before each test - */ - protected function _before(UnitTester $I) - { - require_once dataDir('fixtures/Annotations/TestClass.php'); - } +use function dataDir2; +final class GetClassAnnotationsTest extends TestCase +{ /** * Tests creating empty Reflection object * * @author Phalcon Team * @since 2016-01-26 */ - public function testEmptyReflection(UnitTester $I) + public function testEmptyReflection(): void { $reflection = new Reflection(); $actual = $reflection->getClassAnnotations(); - $I->assertNull($actual); + $this->assertNull($actual); } /** @@ -49,7 +43,7 @@ public function testEmptyReflection(UnitTester $I) * @author Phalcon Team * @since 2016-01-26 */ - public function testParsingARealClass(UnitTester $I) + public function testParsingARealClass(): void { $reader = new Reader(); @@ -61,24 +55,32 @@ public function testParsingARealClass(UnitTester $I) $expected = Collection::class; $actual = $classAnnotations; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $number = 0; foreach ($classAnnotations as $annotation) { $expected = Annotation::class; $actual = $annotation; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $number++; } $expected = 9; $actual = $number; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 9; $actual = $classAnnotations; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); + } + + /** + * executed before each test + */ + protected function setUp(): void + { + require_once dataDir2('fixtures/Annotations/TestClass.php'); } } diff --git a/tests/unit/Annotations/Reflection/GetMethodsAnnotationsCest.php b/tests/unit/Annotations/Reflection/GetMethodsAnnotationsTest.php similarity index 68% rename from tests/unit/Annotations/Reflection/GetMethodsAnnotationsCest.php rename to tests/unit/Annotations/Reflection/GetMethodsAnnotationsTest.php index 8dd32f3aa..1255d6ad7 100644 --- a/tests/unit/Annotations/Reflection/GetMethodsAnnotationsCest.php +++ b/tests/unit/Annotations/Reflection/GetMethodsAnnotationsTest.php @@ -16,45 +16,20 @@ use Phalcon\Annotations\Collection; use Phalcon\Annotations\Reader; use Phalcon\Annotations\Reflection; -use UnitTester; +use PHPUnit\Framework\TestCase; -use function dataDir; +use function dataDir2; -class GetMethodsAnnotationsCest +final class GetMethodsAnnotationsTest extends TestCase { - /** - * executed before each test - */ - protected function _before(UnitTester $I) - { - require_once dataDir('fixtures/Annotations/TestClass.php'); - } - - /** - * Tests creating empty Reflection object - * - * @author Phalcon Team - * @since 2016-01-26 - */ - public function testEmptyReflection(UnitTester $I) - { - $reflection = new Reflection(); - - $actual = $reflection->getMethodsAnnotations(); - $I->assertIsArray($actual); - $I->assertIsEmpty($actual); - } - /** * Tests Phalcon\Annotations\Reflection :: getMethodsAnnotations() * * @author Phalcon Team * @since 2020-02-21 */ - public function annotationsReflectionGetMethodsAnnotations(UnitTester $I) + public function testAnnotationsReflectionGetMethodsAnnotations(): void { - $I->wantToTest('Annotations\Reflection - getMethodsAnnotations()'); - $reader = new Reader(); $reflection = new Reflection( @@ -62,24 +37,47 @@ public function annotationsReflectionGetMethodsAnnotations(UnitTester $I) ); $methodsAnnotations = $reflection->getMethodsAnnotations(); - $I->assertIsArray($methodsAnnotations); + $this->assertIsArray($methodsAnnotations); $number = 0; foreach ($methodsAnnotations as $annotation) { $expected = Collection::class; $actual = $annotation; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $number++; } $expected = 4; $actual = $number; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 4; $actual = $methodsAnnotations; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); + } + + /** + * Tests creating empty Reflection object + * + * @author Phalcon Team + * @since 2016-01-26 + */ + public function testEmptyReflection(): void + { + $reflection = new Reflection(); + + $actual = $reflection->getMethodsAnnotations(); + $this->assertIsArray($actual); + $this->assertEmpty($actual); + } + + /** + * executed before each test + */ + protected function setUp(): void + { + require_once dataDir2('fixtures/Annotations/TestClass.php'); } } diff --git a/tests/unit/Annotations/Reflection/GetPropertiesAnnotationsCest.php b/tests/unit/Annotations/Reflection/GetPropertiesAnnotationsTest.php similarity index 68% rename from tests/unit/Annotations/Reflection/GetPropertiesAnnotationsCest.php rename to tests/unit/Annotations/Reflection/GetPropertiesAnnotationsTest.php index b4bc4363c..1e802ade3 100644 --- a/tests/unit/Annotations/Reflection/GetPropertiesAnnotationsCest.php +++ b/tests/unit/Annotations/Reflection/GetPropertiesAnnotationsTest.php @@ -16,45 +16,20 @@ use Phalcon\Annotations\Collection; use Phalcon\Annotations\Reader; use Phalcon\Annotations\Reflection; -use UnitTester; +use PHPUnit\Framework\TestCase; -use function dataDir; +use function dataDir2; -class GetPropertiesAnnotationsCest +final class GetPropertiesAnnotationsTest extends TestCase { - /** - * executed before each test - */ - protected function _before(UnitTester $I) - { - require_once dataDir('fixtures/Annotations/TestClass.php'); - } - - /** - * Tests creating empty Reflection object - * - * @author Phalcon Team - * @since 2016-01-26 - */ - public function testEmptyReflection(UnitTester $I) - { - $reflection = new Reflection(); - - $actual = $reflection->getPropertiesAnnotations(); - $I->assertIsArray($actual); - $I->assertIsEmpty($actual); - } - /** * Tests Phalcon\Annotations\Reflection :: getPropertiesAnnotations() * * @author Phalcon Team * @since 2020-02-21 */ - public function annotationsReflectionGetPropertiesAnnotations(UnitTester $I) + public function testAnnotationsReflectionGetPropertiesAnnotations(): void { - $I->wantToTest('Annotations\Reflection - getPropertiesAnnotations()'); - $reader = new Reader(); $reflection = new Reflection( @@ -63,24 +38,47 @@ public function annotationsReflectionGetPropertiesAnnotations(UnitTester $I) $propertiesAnnotations = $reflection->getPropertiesAnnotations(); - $I->assertIsArray($propertiesAnnotations); + $this->assertIsArray($propertiesAnnotations); $number = 0; foreach ($propertiesAnnotations as $annotation) { $expected = Collection::class; $actual = $annotation; - $I->assertInstanceOf($expected, $actual); + $this->assertInstanceOf($expected, $actual); $number++; } $expected = 3; $actual = $number; - $I->assertSame($expected, $actual); + $this->assertSame($expected, $actual); $expected = 3; $actual = $propertiesAnnotations; - $I->assertCount($expected, $actual); + $this->assertCount($expected, $actual); + } + + /** + * Tests creating empty Reflection object + * + * @author Phalcon Team + * @since 2016-01-26 + */ + public function testEmptyReflection(): void + { + $reflection = new Reflection(); + + $actual = $reflection->getPropertiesAnnotations(); + $this->assertIsArray($actual); + $this->assertEmpty($actual); + } + + /** + * executed before each test + */ + protected function setUp(): void + { + require_once dataDir2('fixtures/Annotations/TestClass.php'); } } diff --git a/tests/unit/Annotations/Reflection/GetReflectionDataCest.php b/tests/unit/Annotations/Reflection/GetReflectionDataTest.php similarity index 70% rename from tests/unit/Annotations/Reflection/GetReflectionDataCest.php rename to tests/unit/Annotations/Reflection/GetReflectionDataTest.php index 049530c34..a3738429c 100644 --- a/tests/unit/Annotations/Reflection/GetReflectionDataCest.php +++ b/tests/unit/Annotations/Reflection/GetReflectionDataTest.php @@ -14,9 +14,9 @@ namespace Phalcon\Tests\Unit\Annotations\Reflection; use Phalcon\Annotations\Reflection; -use UnitTester; +use PHPUnit\Framework\TestCase; -class GetReflectionDataCest +final class GetReflectionDataTest extends TestCase { /** * Tests Phalcon\Annotations\Reflection :: getReflectionData() @@ -24,14 +24,12 @@ class GetReflectionDataCest * @author Phalcon Team * @since 2018-11-13 */ - public function annotationsReflectionGetReflectionData(UnitTester $I) + public function testAnnotationsReflectionGetReflectionData(): void { - $I->wantToTest('Annotations\Reflection - getReflectionData()'); - $reflection = new Reflection(); $actual = $reflection->getReflectionData(); - $I->assertIsArray($actual); - $I->assertIsEmpty($actual); + $this->assertIsArray($actual); + $this->assertEmpty($actual); } }