From e2a86a447c7cee9360d7a5d52b1a8a5a03db64b4 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Sat, 29 Jun 2024 20:04:42 -0500 Subject: [PATCH 1/7] alignment with cphalcon --- tests/_data/fixtures/Tasks/MainTask.php | 2 +- .../DispatcherParametersController.php | 3 +- tests/cli/Cli/Console/SetArgumentCest.php | 2 +- tests/cli/Cli/Console/UnderscoreGetCest.php | 2 +- .../cli/Cli/Dispatcher/GetActiveTaskCest.php | 2 +- tests/database/Db/Adapter/Pdo/ConnectCest.php | 2 +- tests/database/Db/Adapter/Pdo/DeleteCest.php | 2 +- .../Db/Adapter/Pdo/DescribeColumnsCest.php | 14 +- .../Db/Adapter/Pdo/ExecInsertCest.php | 6 +- tests/database/Db/RawValue/ToStringCest.php | 2 +- .../unit/Acl/Adapter/Memory/IsAllowedCest.php | 2 +- .../Adapter/Apcu/ConstructCest.php | 44 -- .../unit/Annotations/Adapter/Apcu/GetCest.php | 59 -- .../Adapter/Apcu/GetMethodCest.php | 54 -- .../Adapter/Apcu/GetMethodsCest.php | 66 -- .../Adapter/Apcu/GetPropertiesCest.php | 65 -- .../Adapter/Apcu/GetPropertyCest.php | 54 -- .../Adapter/Apcu/GetSetReaderCest.php | 51 -- .../Adapter/Apcu/ReadWriteCest.php | 66 -- tests/unit/Annotations/Adapter/ApcuCest.php | 119 ---- .../Annotations/Adapter/ConstructCest.php | 125 ++++ tests/unit/Annotations/Adapter/GetCest.php | 58 ++ .../Annotations/Adapter/GetMethodCest.php | 57 ++ .../Annotations/Adapter/GetMethodsCest.php | 71 +++ .../Annotations/Adapter/GetPropertiesCest.php | 68 +++ .../Annotations/Adapter/GetPropertyCest.php | 59 ++ .../Annotations/Adapter/GetSetReaderCest.php | 58 ++ .../Adapter/Memory/ConstructCest.php | 39 -- .../Annotations/Adapter/Memory/GetCest.php | 54 -- .../Adapter/Memory/GetMethodCest.php | 49 -- .../Adapter/Memory/GetMethodsCest.php | 61 -- .../Adapter/Memory/GetPropertiesCest.php | 60 -- .../Adapter/Memory/GetPropertyCest.php | 47 -- .../Adapter/Memory/GetSetReaderCest.php | 46 -- .../Adapter/Memory/ReadWriteCest.php | 52 -- tests/unit/Annotations/Adapter/MemoryCest.php | 121 ---- .../Annotations/Adapter/ReadWriteCest.php | 63 ++ .../Adapter/Stream/ConstructCest.php | 45 -- .../Annotations/Adapter/Stream/GetCest.php | 64 -- .../Adapter/Stream/GetMethodCest.php | 56 -- .../Adapter/Stream/GetMethodsCest.php | 69 --- .../Adapter/Stream/GetPropertiesCest.php | 68 --- .../Adapter/Stream/GetPropertyCest.php | 56 -- .../Adapter/Stream/GetSetReaderCest.php | 50 -- .../Annotations/Adapter/Stream/ReadCest.php | 64 -- .../Annotations/Adapter/Stream/WriteCest.php | 57 -- .../Annotation/GetArgumentCest.php | 4 +- .../Annotation/GetArgumentsCest.php | 2 +- .../Annotation/GetExprArgumentsCest.php | 2 +- .../Annotation/GetExpressionCest.php | 4 +- .../Annotations/Annotation/GetNameCest.php | 2 +- .../Annotation/GetNamedArgumentCest.php | 4 +- .../Annotation/GetNamedParameterCest.php | 4 +- .../Annotation/NumberArgumentsCest.php | 2 +- .../Annotations/Collection/ConstructCest.php | 14 +- .../unit/Annotations/Collection/CountCest.php | 4 +- .../Annotations/Collection/GetAllCest.php | 11 +- .../Collection/GetAnnotationsCest.php | 6 +- tests/unit/Annotations/Collection/GetCest.php | 6 +- tests/unit/Annotations/Collection/HasCest.php | 6 +- .../Collection/KeyNextRewindCest.php | 24 +- .../unit/Annotations/Collection/ValidCest.php | 14 +- tests/unit/Annotations/Reader/ParseCest.php | 568 ++++++++++++++---- .../Annotations/Reader/ParseDocBlockCest.php | 166 ++--- .../Annotations/Reflection/ConstructCest.php | 155 +++++ .../Reflection/GetClassAnnotationsCest.php | 28 +- .../Reflection/GetMethodsAnnotationsCest.php | 26 +- .../GetPropertiesAnnotationsCest.php | 25 +- .../Reflection/GetReflectionDataCest.php | 5 +- tests/unit/Annotations/ReflectionCest.php | 141 ----- tests/unit/Di/GetDICest.php | 6 +- .../Di/GetSetInternalEventsManagerCest.php | 3 +- .../unit/Di/Injectable/UnderscoreGetCest.php | 17 +- tests/unit/Encryption/Crypt/EncryptCest.php | 5 +- tests/unit/Html/Attributes/ToStringCest.php | 28 + tests/unit/Html/Helper/Meta/ToStringCest.php | 40 ++ tests/unit/Http/Cookie/ConstructCest.php | 16 +- .../Adapter/Noop/SerializeUnserializeCest.php | 2 +- .../Stream/SerializeUnserializeCest.php | 2 +- .../Syslog/SerializeUnserializeCest.php | 2 +- .../unit/Logger/Formatter/Json/FormatCest.php | 2 +- tests/unit/Logger/Logger/LogCest.php | 50 -- tests/unit/Tag/AppendTitleCest.php | 187 ++++++ tests/unit/Tag/CheckFieldCest.php | 139 +++++ tests/unit/Tag/ColorFieldCest.php | 22 + tests/unit/Tag/DateFieldCest.php | 22 + tests/unit/Tag/DateTimeFieldCest.php | 22 + tests/unit/Tag/DateTimeLocalFieldCest.php | 22 + tests/unit/Tag/DisplayToCest.php | 65 ++ tests/unit/Tag/EmailFieldCest.php | 22 + tests/unit/Tag/EndFormCest.php | 35 ++ tests/unit/Tag/FileFieldCest.php | 22 + tests/unit/Tag/FormLegacyCest.php | 41 ++ tests/unit/Tag/FriendlyTitleCest.php | 181 ++++++ tests/unit/Tag/GetDocTypeCest.php | 143 +++++ tests/unit/Tag/GetEscaperCest.php | 44 ++ tests/unit/Tag/GetEscaperServiceCest.php | 41 ++ tests/unit/Tag/GetHasValueCest.php | 66 ++ tests/unit/Tag/GetSetDICest.php | 49 ++ tests/unit/Tag/GetSetTitleSeparatorCest.php | 38 ++ tests/unit/Tag/GetTitleCest.php | 43 ++ tests/unit/Tag/GetUrlServiceCest.php | 39 ++ tests/unit/Tag/HiddenFieldCest.php | 22 + tests/unit/Tag/ImageCest.php | 305 ++++++++++ tests/unit/Tag/ImageInputCest.php | 370 ++++++++++++ tests/unit/Tag/JavascriptIncludeCest.php | 132 ++++ tests/unit/Tag/LinkToCest.php | 240 ++++++++ tests/unit/Tag/MonthFieldCest.php | 22 + tests/unit/Tag/NumericFieldCest.php | 22 + tests/unit/Tag/PasswordFieldCest.php | 22 + tests/unit/Tag/PrependTitleCest.php | 191 ++++++ tests/unit/Tag/RadioFieldCest.php | 44 ++ tests/unit/Tag/RangeFieldCest.php | 22 + tests/unit/Tag/RenderAttributesCest.php | 41 ++ tests/unit/Tag/RenderTitleCest.php | 43 ++ tests/unit/Tag/ResetInputCest.php | 134 +++++ tests/unit/Tag/SearchFieldCest.php | 22 + tests/unit/Tag/SetDefaultCest.php | 68 +++ tests/unit/Tag/SetDefaultsCest.php | 71 +++ tests/unit/Tag/SetDocTypeCest.php | 33 + tests/unit/Tag/SetTitleCest.php | 47 ++ tests/unit/Tag/StylesheetLinkCest.php | 225 +++++++ tests/unit/Tag/SubmitButtonCest.php | 196 ++++++ tests/unit/Tag/TagHtmlCest.php | 209 +++++++ tests/unit/Tag/TagHtmlCloseCest.php | 95 +++ tests/unit/Tag/TelFieldCest.php | 22 + tests/unit/Tag/TextAreaCest.php | 212 +++++++ tests/unit/Tag/TextFieldCest.php | 22 + tests/unit/Tag/TimeFieldCest.php | 22 + tests/unit/Tag/UrlFieldCest.php | 22 + tests/unit/Tag/WeekFieldCest.php | 22 + 131 files changed, 5611 insertions(+), 2160 deletions(-) delete mode 100644 tests/unit/Annotations/Adapter/Apcu/ConstructCest.php delete mode 100644 tests/unit/Annotations/Adapter/Apcu/GetCest.php delete mode 100644 tests/unit/Annotations/Adapter/Apcu/GetMethodCest.php delete mode 100644 tests/unit/Annotations/Adapter/Apcu/GetMethodsCest.php delete mode 100644 tests/unit/Annotations/Adapter/Apcu/GetPropertiesCest.php delete mode 100644 tests/unit/Annotations/Adapter/Apcu/GetPropertyCest.php delete mode 100644 tests/unit/Annotations/Adapter/Apcu/GetSetReaderCest.php delete mode 100644 tests/unit/Annotations/Adapter/Apcu/ReadWriteCest.php delete mode 100644 tests/unit/Annotations/Adapter/ApcuCest.php create mode 100644 tests/unit/Annotations/Adapter/ConstructCest.php create mode 100644 tests/unit/Annotations/Adapter/GetCest.php create mode 100644 tests/unit/Annotations/Adapter/GetMethodCest.php create mode 100644 tests/unit/Annotations/Adapter/GetMethodsCest.php create mode 100644 tests/unit/Annotations/Adapter/GetPropertiesCest.php create mode 100644 tests/unit/Annotations/Adapter/GetPropertyCest.php create mode 100644 tests/unit/Annotations/Adapter/GetSetReaderCest.php delete mode 100644 tests/unit/Annotations/Adapter/Memory/ConstructCest.php delete mode 100644 tests/unit/Annotations/Adapter/Memory/GetCest.php delete mode 100644 tests/unit/Annotations/Adapter/Memory/GetMethodCest.php delete mode 100644 tests/unit/Annotations/Adapter/Memory/GetMethodsCest.php delete mode 100644 tests/unit/Annotations/Adapter/Memory/GetPropertiesCest.php delete mode 100644 tests/unit/Annotations/Adapter/Memory/GetPropertyCest.php delete mode 100644 tests/unit/Annotations/Adapter/Memory/GetSetReaderCest.php delete mode 100644 tests/unit/Annotations/Adapter/Memory/ReadWriteCest.php delete mode 100644 tests/unit/Annotations/Adapter/MemoryCest.php create mode 100644 tests/unit/Annotations/Adapter/ReadWriteCest.php delete mode 100644 tests/unit/Annotations/Adapter/Stream/ConstructCest.php delete mode 100644 tests/unit/Annotations/Adapter/Stream/GetCest.php delete mode 100644 tests/unit/Annotations/Adapter/Stream/GetMethodCest.php delete mode 100644 tests/unit/Annotations/Adapter/Stream/GetMethodsCest.php delete mode 100644 tests/unit/Annotations/Adapter/Stream/GetPropertiesCest.php delete mode 100644 tests/unit/Annotations/Adapter/Stream/GetPropertyCest.php delete mode 100644 tests/unit/Annotations/Adapter/Stream/GetSetReaderCest.php delete mode 100644 tests/unit/Annotations/Adapter/Stream/ReadCest.php delete mode 100644 tests/unit/Annotations/Adapter/Stream/WriteCest.php delete mode 100644 tests/unit/Annotations/ReflectionCest.php create mode 100644 tests/unit/Tag/AppendTitleCest.php create mode 100644 tests/unit/Tag/CheckFieldCest.php create mode 100644 tests/unit/Tag/ColorFieldCest.php create mode 100644 tests/unit/Tag/DateFieldCest.php create mode 100644 tests/unit/Tag/DateTimeFieldCest.php create mode 100644 tests/unit/Tag/DateTimeLocalFieldCest.php create mode 100644 tests/unit/Tag/DisplayToCest.php create mode 100644 tests/unit/Tag/EmailFieldCest.php create mode 100644 tests/unit/Tag/EndFormCest.php create mode 100644 tests/unit/Tag/FileFieldCest.php create mode 100644 tests/unit/Tag/FormLegacyCest.php create mode 100644 tests/unit/Tag/FriendlyTitleCest.php create mode 100644 tests/unit/Tag/GetDocTypeCest.php create mode 100644 tests/unit/Tag/GetEscaperCest.php create mode 100644 tests/unit/Tag/GetEscaperServiceCest.php create mode 100644 tests/unit/Tag/GetHasValueCest.php create mode 100644 tests/unit/Tag/GetSetDICest.php create mode 100644 tests/unit/Tag/GetSetTitleSeparatorCest.php create mode 100644 tests/unit/Tag/GetTitleCest.php create mode 100644 tests/unit/Tag/GetUrlServiceCest.php create mode 100644 tests/unit/Tag/HiddenFieldCest.php create mode 100644 tests/unit/Tag/ImageCest.php create mode 100644 tests/unit/Tag/ImageInputCest.php create mode 100644 tests/unit/Tag/JavascriptIncludeCest.php create mode 100644 tests/unit/Tag/LinkToCest.php create mode 100644 tests/unit/Tag/MonthFieldCest.php create mode 100644 tests/unit/Tag/NumericFieldCest.php create mode 100644 tests/unit/Tag/PasswordFieldCest.php create mode 100644 tests/unit/Tag/PrependTitleCest.php create mode 100644 tests/unit/Tag/RadioFieldCest.php create mode 100644 tests/unit/Tag/RangeFieldCest.php create mode 100644 tests/unit/Tag/RenderAttributesCest.php create mode 100644 tests/unit/Tag/RenderTitleCest.php create mode 100644 tests/unit/Tag/ResetInputCest.php create mode 100644 tests/unit/Tag/SearchFieldCest.php create mode 100644 tests/unit/Tag/SetDefaultCest.php create mode 100644 tests/unit/Tag/SetDefaultsCest.php create mode 100644 tests/unit/Tag/SetDocTypeCest.php create mode 100644 tests/unit/Tag/SetTitleCest.php create mode 100644 tests/unit/Tag/StylesheetLinkCest.php create mode 100644 tests/unit/Tag/SubmitButtonCest.php create mode 100644 tests/unit/Tag/TagHtmlCest.php create mode 100644 tests/unit/Tag/TagHtmlCloseCest.php create mode 100644 tests/unit/Tag/TelFieldCest.php create mode 100644 tests/unit/Tag/TextAreaCest.php create mode 100644 tests/unit/Tag/TextFieldCest.php create mode 100644 tests/unit/Tag/TimeFieldCest.php create mode 100644 tests/unit/Tag/UrlFieldCest.php create mode 100644 tests/unit/Tag/WeekFieldCest.php diff --git a/tests/_data/fixtures/Tasks/MainTask.php b/tests/_data/fixtures/Tasks/MainTask.php index cca2638d309..c3f2fd4d5df 100644 --- a/tests/_data/fixtures/Tasks/MainTask.php +++ b/tests/_data/fixtures/Tasks/MainTask.php @@ -45,7 +45,7 @@ public function argumentsAction( string $world, string $symbol, string $country, - $last + mixed $last ) { return '-' . $world . '-' . $symbol . '-' . $country . '-' . (string) $last . '-'; } diff --git a/tests/_data/fixtures/controllers/DispatcherParametersController.php b/tests/_data/fixtures/controllers/DispatcherParametersController.php index 8677735e222..a8220fe9443 100644 --- a/tests/_data/fixtures/controllers/DispatcherParametersController.php +++ b/tests/_data/fixtures/controllers/DispatcherParametersController.php @@ -13,9 +13,10 @@ namespace Phalcon\Tests\Controllers; +use Phalcon\Mvc\Controller; use Phalcon\Mvc\Dispatcher; -class DispatcherParametersController +class DispatcherParametersController extends Controller { public function afterExecuteRoute(Dispatcher $dispatcher) { diff --git a/tests/cli/Cli/Console/SetArgumentCest.php b/tests/cli/Cli/Console/SetArgumentCest.php index dcabec981f1..7250add23fd 100644 --- a/tests/cli/Cli/Console/SetArgumentCest.php +++ b/tests/cli/Cli/Console/SetArgumentCest.php @@ -111,7 +111,7 @@ function () { $expected = [ 'country' => 'usa', - 'last' => true, + 'last' => true, ]; $actual = $dispatcher->getOptions(); $I->assertSame($expected, $actual); diff --git a/tests/cli/Cli/Console/UnderscoreGetCest.php b/tests/cli/Cli/Console/UnderscoreGetCest.php index a6aa5dc6afb..fddde70591c 100644 --- a/tests/cli/Cli/Console/UnderscoreGetCest.php +++ b/tests/cli/Cli/Console/UnderscoreGetCest.php @@ -36,7 +36,7 @@ public function cliConsoleUnderscoreGet(CliTester $I) $container = new DiFactoryDefault(); $console = new CliConsole($container); - $class = Dispatcher::class; + $class = Dispatcher::class; $actual = $console->dispatcher; $I->assertInstanceOf($class, $actual); diff --git a/tests/cli/Cli/Dispatcher/GetActiveTaskCest.php b/tests/cli/Cli/Dispatcher/GetActiveTaskCest.php index 042090d4d74..47a958b976d 100644 --- a/tests/cli/Cli/Dispatcher/GetActiveTaskCest.php +++ b/tests/cli/Cli/Dispatcher/GetActiveTaskCest.php @@ -38,7 +38,7 @@ public function cliDispatcherGetActiveTask(CliTester $I) $dispatcher->setTaskName("main"); $dispatcher->dispatch(); - $class = MainTask::class; + $class = MainTask::class; $actual = $dispatcher->getActiveTask(); $I->assertInstanceOf($class, $actual); } diff --git a/tests/database/Db/Adapter/Pdo/ConnectCest.php b/tests/database/Db/Adapter/Pdo/ConnectCest.php index 841926f59a2..270cd422252 100644 --- a/tests/database/Db/Adapter/Pdo/ConnectCest.php +++ b/tests/database/Db/Adapter/Pdo/ConnectCest.php @@ -50,7 +50,7 @@ public function dbAdapterPdoConnectPersistent(DatabaseTester $I) { $I->wantToTest('Db\Adapter\Pdo - connect() - supported'); - $options = getOptionsMysql(); + $options = getOptionsMysql(); $options['persistent'] = true; $options['options'] = [ PDO::ATTR_EMULATE_PREPARES => false, diff --git a/tests/database/Db/Adapter/Pdo/DeleteCest.php b/tests/database/Db/Adapter/Pdo/DeleteCest.php index 9653e2f21f9..bed289c51ed 100644 --- a/tests/database/Db/Adapter/Pdo/DeleteCest.php +++ b/tests/database/Db/Adapter/Pdo/DeleteCest.php @@ -32,7 +32,7 @@ public function _before(DatabaseTester $I) * Tests Phalcon\Db\Adapter\AbstractAdapter :: delete() * * @author Phalcon Team - * @since 2021-05-10 + * @since 2021-05-10 * * @group pgsql * @group mysql diff --git a/tests/database/Db/Adapter/Pdo/DescribeColumnsCest.php b/tests/database/Db/Adapter/Pdo/DescribeColumnsCest.php index de477c0712d..1b7bf186ae0 100644 --- a/tests/database/Db/Adapter/Pdo/DescribeColumnsCest.php +++ b/tests/database/Db/Adapter/Pdo/DescribeColumnsCest.php @@ -14,6 +14,7 @@ namespace Phalcon\Tests\Database\Db\Adapter\Pdo; use DatabaseTester; +use Phalcon\Db\Adapter\Pdo\Mysql; use Phalcon\Db\Column; use Phalcon\Tests\Fixtures\Migrations\ComplexDefaultMigration; use Phalcon\Tests\Fixtures\Migrations\DialectMigration; @@ -50,6 +51,7 @@ public function dbAdapterPdoDescribeColumnsSupported(DatabaseTester $I) { $I->wantToTest('Db\Adapter\Pdo - describeColumns() - supported'); + /** @var Mysql $db */ $db = $this->container->get('db'); $migration = new DialectMigration($I->getConnection()); $columns = $db->describeColumns($migration->getTable()); @@ -58,7 +60,7 @@ public function dbAdapterPdoDescribeColumnsSupported(DatabaseTester $I) $I->assertCount($expected, $columns); $expected = Column::class; - $actual = $columns[1]; + $actual = $columns[1]; $I->assertInstanceOf($expected, $actual); foreach ($columns as $index => $column) { @@ -67,8 +69,6 @@ public function dbAdapterPdoDescribeColumnsSupported(DatabaseTester $I) $I->assertEquals($expected, $actual); } - - $I->assertEquals($expected, $actual); } /** @@ -85,8 +85,8 @@ public function dbAdapterPdoDescribeColumnsOnUpdate(DatabaseTester $I) { $I->wantToTest('Db\Adapter\Pdo - describeColumns()'); - $db = $this->container->get('db'); - $now = date('Y-m-d H:i:s'); + $db = $this->container->get('db'); + $now = date('Y-m-d H:i:s'); $migration = new ComplexDefaultMigration($I->getConnection()); $migration->insert(1, $now, $now); @@ -110,8 +110,8 @@ public function dbAdapterPdoDescribeColumnsDefaultPostgres(DatabaseTester $I) { $I->wantToTest('Db\Adapter\Pdo - describeColumns() - CheckPostgres Default value'); - $db = $this->container->get('db'); - $now = date('Y-m-d H:i:s'); + $db = $this->container->get('db'); + $now = date('Y-m-d H:i:s'); $migration = new ComplexDefaultMigration($I->getConnection()); $migration->insert(1, $now, $now); diff --git a/tests/database/Db/Adapter/Pdo/ExecInsertCest.php b/tests/database/Db/Adapter/Pdo/ExecInsertCest.php index 992ee2dd2ec..534bda5b265 100644 --- a/tests/database/Db/Adapter/Pdo/ExecInsertCest.php +++ b/tests/database/Db/Adapter/Pdo/ExecInsertCest.php @@ -67,7 +67,7 @@ public function dbAdapterPdoInsert(DatabaseTester $I) $connection = $I->getConnection(); $migration = new DialectMigration($connection); - $sql = <<assertEquals( 'example string', - (string) $rawValue + (string)$rawValue ); } } diff --git a/tests/unit/Acl/Adapter/Memory/IsAllowedCest.php b/tests/unit/Acl/Adapter/Memory/IsAllowedCest.php index b142b3ee06b..0c304ff58ba 100644 --- a/tests/unit/Acl/Adapter/Memory/IsAllowedCest.php +++ b/tests/unit/Acl/Adapter/Memory/IsAllowedCest.php @@ -13,7 +13,7 @@ namespace Phalcon\Tests\Unit\Acl\Adapter\Memory; -use Codeception\Util\Stub; +use Codeception\Stub; use Exception; use Phalcon\Acl\Adapter\Memory; use Phalcon\Acl\Component; diff --git a/tests/unit/Annotations/Adapter/Apcu/ConstructCest.php b/tests/unit/Annotations/Adapter/Apcu/ConstructCest.php deleted file mode 100644 index 82faa132d60..00000000000 --- a/tests/unit/Annotations/Adapter/Apcu/ConstructCest.php +++ /dev/null @@ -1,44 +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\Apcu; - -use Phalcon\Annotations\Adapter\AdapterInterface; -use Phalcon\Annotations\Adapter\Apcu; -use UnitTester; - -class ConstructCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Apcu :: __construct() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterApcuConstruct(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Apcu - __construct()'); - - $oAdapter = new Apcu( - [ - 'prefix' => 'nova_prefix', - 'lifetime' => 3600, - ] - ); - - $I->assertInstanceOf( - AdapterInterface::class, - $oAdapter - ); - } -} diff --git a/tests/unit/Annotations/Adapter/Apcu/GetCest.php b/tests/unit/Annotations/Adapter/Apcu/GetCest.php deleted file mode 100644 index 16aff5f0aaa..00000000000 --- a/tests/unit/Annotations/Adapter/Apcu/GetCest.php +++ /dev/null @@ -1,59 +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\Apcu; - -use Phalcon\Annotations\Adapter\Apcu; -use Phalcon\Annotations\Collection; -use Phalcon\Annotations\Reflection; -use TestClass; -use UnitTester; - -class GetCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Apcu :: get() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterApcuGet(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Apcu - get()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $oAdapter = new Apcu( - [ - 'prefix' => 'nova_prefix', - 'lifetime' => 3600, - ] - ); - - $oClassAnnotations = $oAdapter->get( - TestClass::class - ); - - $I->assertTrue(is_object($oClassAnnotations)); - - $I->assertInstanceOf( - Reflection::class, - $oClassAnnotations - ); - - $I->assertInstanceOf( - Collection::class, - $oClassAnnotations->getClassAnnotations() - ); - } -} diff --git a/tests/unit/Annotations/Adapter/Apcu/GetMethodCest.php b/tests/unit/Annotations/Adapter/Apcu/GetMethodCest.php deleted file mode 100644 index 425d0e92fa8..00000000000 --- a/tests/unit/Annotations/Adapter/Apcu/GetMethodCest.php +++ /dev/null @@ -1,54 +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\Apcu; - -use Phalcon\Annotations\Adapter\Apcu; -use Phalcon\Annotations\Collection; -use TestClass; -use UnitTester; - -use function dataDir; - -class GetMethodCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Apcu :: getMethod() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterApcuGetMethod(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Apcu - getMethod()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $oAdapter = new Apcu( - [ - 'prefix' => 'nova_prefix', - 'lifetime' => 3600, - ] - ); - - $sMethodAnnotation = $oAdapter->getMethod( - TestClass::class, - 'testMethod1' - ); - - $I->assertInstanceOf( - Collection::class, - $sMethodAnnotation - ); - } -} diff --git a/tests/unit/Annotations/Adapter/Apcu/GetMethodsCest.php b/tests/unit/Annotations/Adapter/Apcu/GetMethodsCest.php deleted file mode 100644 index c9cea54720c..00000000000 --- a/tests/unit/Annotations/Adapter/Apcu/GetMethodsCest.php +++ /dev/null @@ -1,66 +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\Apcu; - -use Phalcon\Annotations\Adapter\Apcu; -use Phalcon\Annotations\Collection; -use TestClass; -use UnitTester; - -use function dataDir; - -class GetMethodsCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Apcu :: getMethods() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterApcuGetMethods(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Apcu - getMethods()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $oAdapter = new Apcu( - [ - 'prefix' => 'nova_prefix', - 'lifetime' => 3600, - ] - ); - - $aMethodAnnotations = $oAdapter->getMethods( - TestClass::class - ); - - $aKeys = array_keys($aMethodAnnotations); - $I->assertEquals( - [ - 'testMethod1', - 'testMethod3', - 'testMethod4', - 'testMethod5', - ], - $aKeys - ); - - foreach ($aMethodAnnotations as $oMethodAnnotation) { - $I->assertInstanceOf( - Collection::class, - $oMethodAnnotation - ); - } - } -} diff --git a/tests/unit/Annotations/Adapter/Apcu/GetPropertiesCest.php b/tests/unit/Annotations/Adapter/Apcu/GetPropertiesCest.php deleted file mode 100644 index 801d0464251..00000000000 --- a/tests/unit/Annotations/Adapter/Apcu/GetPropertiesCest.php +++ /dev/null @@ -1,65 +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\Apcu; - -use Phalcon\Annotations\Adapter\Apcu; -use Phalcon\Annotations\Collection; -use TestClass; -use UnitTester; - -use function dataDir; - -class GetPropertiesCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Apcu :: getProperties() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterApcuGetProperties(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Apcu - getProperties()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $oAdapter = new Apcu( - [ - 'prefix' => 'nova_prefix', - 'lifetime' => 3600, - ] - ); - - $aPropertyAnnotations = $oAdapter->getProperties( - TestClass::class - ); - - $aKeys = array_keys($aPropertyAnnotations); - $I->assertEquals( - [ - 'testProp1', - 'testProp3', - 'testProp4', - ], - $aKeys - ); - - foreach ($aPropertyAnnotations as $oPropertyAnnotation) { - $I->assertInstanceOf( - Collection::class, - $oPropertyAnnotation - ); - } - } -} diff --git a/tests/unit/Annotations/Adapter/Apcu/GetPropertyCest.php b/tests/unit/Annotations/Adapter/Apcu/GetPropertyCest.php deleted file mode 100644 index 59df0ee3463..00000000000 --- a/tests/unit/Annotations/Adapter/Apcu/GetPropertyCest.php +++ /dev/null @@ -1,54 +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\Apcu; - -use Phalcon\Annotations\Adapter\Apcu; -use Phalcon\Annotations\Collection; -use TestClass; -use UnitTester; - -use function dataDir; - -class GetPropertyCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Apcu :: getProperty() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterApcuGetProperty(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Apcu - getProperty()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $oAdapter = new Apcu( - [ - 'prefix' => 'nova_prefix', - 'lifetime' => 3600, - ] - ); - - $oPropertyAnnotations = $oAdapter->getProperty( - TestClass::class, - 'testProp1' - ); - - $I->assertInstanceOf( - Collection::class, - $oPropertyAnnotations - ); - } -} diff --git a/tests/unit/Annotations/Adapter/Apcu/GetSetReaderCest.php b/tests/unit/Annotations/Adapter/Apcu/GetSetReaderCest.php deleted file mode 100644 index 19fa3664e09..00000000000 --- a/tests/unit/Annotations/Adapter/Apcu/GetSetReaderCest.php +++ /dev/null @@ -1,51 +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\Apcu; - -use Phalcon\Annotations\Adapter\Apcu; -use Phalcon\Annotations\Reader; -use UnitTester; - -class GetSetReaderCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Apcu :: getReader() / setReader() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterApcuGetSetReader(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Apcu - getReader() / setReader'); - - $oAdapter = new Apcu( - [ - 'prefix' => 'nova_prefix', - 'lifetime' => 3600, - ] - ); - - $oReader = new Reader(); - $oAdapter->setReader($oReader); - - $I->assertSame( - $oReader, - $oAdapter->getReader() - ); - - $oClass = Reader::class; - $oActual = $oAdapter->getReader(); - $I->assertInstanceOf($oClass, $oActual); - } -} diff --git a/tests/unit/Annotations/Adapter/Apcu/ReadWriteCest.php b/tests/unit/Annotations/Adapter/Apcu/ReadWriteCest.php deleted file mode 100644 index d0990617e92..00000000000 --- a/tests/unit/Annotations/Adapter/Apcu/ReadWriteCest.php +++ /dev/null @@ -1,66 +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\Apcu; - -use Phalcon\Annotations\Adapter\Apcu; -use Phalcon\Annotations\Reflection; -use TestClass; -use UnitTester; - -use function dataDir; - -class ReadWriteCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Apcu :: read() / write() - * - * @author Phalcon Team - * @since 2018-11-13 - */ - public function annotationsAdapterApcuReadWrite(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Apcu - read() / write()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $sPrefix = 'nova_prefix'; - $sKey = 'testwrite'; - - $oAdapter = new Apcu( - [ - 'prefix' => $sPrefix, - 'lifetime' => 3600, - ] - ); - - $oClassAnnotations = $oAdapter->get( - TestClass::class - ); - - $oAdapter->write($sKey, $oClassAnnotations); - - $oNewClass = $oAdapter->read('testwrite'); - - $I->assertInstanceOf( - Reflection::class, - $oNewClass - ); - - // Check APC value with Codecept - $sKeyAPC = strtolower("_PHAN" . $sPrefix . $sKey); - - $I->seeInApc($sKeyAPC); - $I->seeInApc($sKeyAPC, $oClassAnnotations); - } -} diff --git a/tests/unit/Annotations/Adapter/ApcuCest.php b/tests/unit/Annotations/Adapter/ApcuCest.php deleted file mode 100644 index f9a99017293..00000000000 --- a/tests/unit/Annotations/Adapter/ApcuCest.php +++ /dev/null @@ -1,119 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE.txt - * file that was distributed with this source code. - */ - -namespace Phalcon\Tests\Unit\Annotations\Adapter; - -use Phalcon\Annotations\Adapter\Apcu; -use Phalcon\Annotations\Collection; -use Phalcon\Annotations\Reflection; -use TestClass; -use UnitTester; -use User\TestClassNs; - -class ApcuCest -{ - /** - * executed before each test - */ - public function _before(UnitTester $I) - { - $I->checkExtensionIsLoaded('apcu'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - require_once dataDir('fixtures/Annotations/TestClassNs.php'); - } - - public function testApcAdapter(UnitTester $I) - { - $adapter = new Apcu(); - - $classAnnotations = $adapter->get( - TestClass::class - ); - - $I->assertTrue(is_object($classAnnotations)); - - $I->assertInstanceOf( - Reflection::class, - $classAnnotations - ); - - $I->assertInstanceOf( - Collection::class, - $classAnnotations->getClassAnnotations() - ); - - $classAnnotations = $adapter->get( - TestClass::class - ); - - $I->assertTrue(is_object($classAnnotations)); - - $I->assertInstanceOf( - Reflection::class, - $classAnnotations - ); - - $I->assertInstanceOf( - Collection::class, - $classAnnotations->getClassAnnotations() - ); - - $classAnnotations = $adapter->get( - TestClassNs::class - ); - - $I->assertTrue(is_object($classAnnotations)); - - $I->assertInstanceOf( - Reflection::class, - $classAnnotations - ); - - $I->assertInstanceOf( - Collection::class, - $classAnnotations->getClassAnnotations() - ); - - $classAnnotations = $adapter->get( - TestClassNs::class - ); - - $I->assertTrue(is_object($classAnnotations)); - - $I->assertInstanceOf( - Reflection::class, - $classAnnotations - ); - - $I->assertInstanceOf( - Collection::class, - $classAnnotations->getClassAnnotations() - ); - - $property = $adapter->getProperty( - TestClass::class, - 'testProp1' - ); - - $I->assertTrue(is_object($property)); - - $I->assertInstanceOf( - Collection::class, - $property - ); - - $I->assertEquals( - 4, - $property->count() - ); - } -} diff --git a/tests/unit/Annotations/Adapter/ConstructCest.php b/tests/unit/Annotations/Adapter/ConstructCest.php new file mode 100644 index 00000000000..e191baf4beb --- /dev/null +++ b/tests/unit/Annotations/Adapter/ConstructCest.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. + */ + +declare(strict_types=1); + +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 TestClass; +use UnitTester; +use User\TestClassNs; + +use function dataDir; +use function is_object; + +class ConstructCest +{ + use AnnotationsTrait; + + /** + * Tests Phalcon\Annotations\Adapter :: __construct() + * + * @dataProvider getExamples + * + * @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 :: + * + * @dataProvider getExamples + * + * @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') + ); + + $I->seeFileFound( + dataDir('fixtures/Annotations/TestClassNs.php') + ); + + require_once dataDir('fixtures/Annotations/TestClass.php'); + require_once dataDir('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); + + $expected = Reflection::class; + $actual = $classAnnotations; + $I->assertInstanceOf($expected, $actual); + + $expected = Collection::class; + $actual = $classAnnotations->getClassAnnotations(); + $I->assertInstanceOf($expected, $actual); + + $classAnnotations = $adapter->get(TestClassNs::class); + + $actual = is_object($classAnnotations); + $I->assertTrue($actual); + + $expected = Reflection::class; + $actual = $classAnnotations; + $I->assertInstanceOf($expected, $actual); + + $expected = Collection::class; + $actual = $classAnnotations->getClassAnnotations(); + $I->assertInstanceOf($expected, $actual); + + + $property = $adapter->getProperty( + TestClass::class, + 'testProp1' + ); + + $actual = is_object($property); + $I->assertTrue($actual); + + $expected = Collection::class; + $actual = $property; + $I->assertInstanceOf($expected, $actual); + + $expected = 4; + $actual = $property->count(); + $I->assertSame($expected, $actual); + } +} diff --git a/tests/unit/Annotations/Adapter/GetCest.php b/tests/unit/Annotations/Adapter/GetCest.php new file mode 100644 index 00000000000..c20c902f02f --- /dev/null +++ b/tests/unit/Annotations/Adapter/GetCest.php @@ -0,0 +1,58 @@ + + * + * 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\Annotations\Reflection; +use Phalcon\Tests\Fixtures\Traits\AnnotationsTrait; +use TestClass; +use UnitTester; + +class GetCest +{ + use AnnotationsTrait; + + /** + * Tests Phalcon\Annotations\Adapter :: get() + * + * @dataProvider getExamples + * + * @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'); + + $class = $example['class']; + $params = $example['params']; + $adapter = new $class($params); + + $classAnnotations = $adapter->get(TestClass::class); + + $actual = is_object($classAnnotations); + $I->assertTrue($actual); + + $expected = Reflection::class; + $actual = $classAnnotations; + $I->assertInstanceOf($expected, $actual); + + $expected = Collection::class; + $actual = $classAnnotations->getClassAnnotations(); + $I->assertInstanceOf($expected, $actual); + } +} diff --git a/tests/unit/Annotations/Adapter/GetMethodCest.php b/tests/unit/Annotations/Adapter/GetMethodCest.php new file mode 100644 index 00000000000..3b8ce45e8d9 --- /dev/null +++ b/tests/unit/Annotations/Adapter/GetMethodCest.php @@ -0,0 +1,57 @@ + + * + * 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 new file mode 100644 index 00000000000..11eb4618010 --- /dev/null +++ b/tests/unit/Annotations/Adapter/GetMethodsCest.php @@ -0,0 +1,71 @@ + + * + * 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/GetPropertiesCest.php b/tests/unit/Annotations/Adapter/GetPropertiesCest.php new file mode 100644 index 00000000000..4a10a21129f --- /dev/null +++ b/tests/unit/Annotations/Adapter/GetPropertiesCest.php @@ -0,0 +1,68 @@ + + * + * 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 GetPropertiesCest +{ + use AnnotationsTrait; + + /** + * Tests Phalcon\Annotations\Adapter :: getProperties() + * + * @dataProvider getExamples + * + * @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'); + + $class = $example['class']; + $params = $example['params']; + $adapter = new $class($params); + + $propertyAnnotations = $adapter->getProperties(TestClass::class); + + $keys = array_keys($propertyAnnotations); + $expected = [ + 'testProp1', + 'testProp3', + 'testProp4', + ]; + $actual = $keys; + $I->assertSame($expected, $actual); + + foreach ($propertyAnnotations as $propertyAnnotation) { + $expected = Collection::class; + $actual = $propertyAnnotation; + $I->assertInstanceOf($expected, $actual); + } + + $I->safeDeleteFile('testclass.php'); + } +} diff --git a/tests/unit/Annotations/Adapter/GetPropertyCest.php b/tests/unit/Annotations/Adapter/GetPropertyCest.php new file mode 100644 index 00000000000..b27eb1fa5c0 --- /dev/null +++ b/tests/unit/Annotations/Adapter/GetPropertyCest.php @@ -0,0 +1,59 @@ + + * + * 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 GetPropertyCest +{ + use AnnotationsTrait; + + /** + * Tests Phalcon\Annotations\Adapter :: getProperty() + * + * @dataProvider getExamples + * + * @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'); + + $class = $example['class']; + $params = $example['params']; + $adapter = new $class($params); + + $propertyAnnotation = $adapter->getProperty( + TestClass::class, + 'testProp1' + ); + + $expected = Collection::class; + $actual = $propertyAnnotation; + $I->assertInstanceOf($expected, $actual); + + $I->safeDeleteFile('testclass.php'); + } +} diff --git a/tests/unit/Annotations/Adapter/GetSetReaderCest.php b/tests/unit/Annotations/Adapter/GetSetReaderCest.php new file mode 100644 index 00000000000..8e7f4882f8c --- /dev/null +++ b/tests/unit/Annotations/Adapter/GetSetReaderCest.php @@ -0,0 +1,58 @@ + + * + * 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\Reader; +use Phalcon\Tests\Fixtures\Traits\AnnotationsTrait; +use UnitTester; + +use function dataDir; + +class GetSetReaderCest +{ + use AnnotationsTrait; + + /** + * Tests Phalcon\Annotations\Adapter :: getReader()/setReader() + * + * @dataProvider getExamples + * + * @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'); + + $class = $example['class']; + $params = $example['params']; + $adapter = new $class($params); + + $reader = new Reader(); + $adapter->setReader($reader); + + $expected = $reader; + $actual = $adapter->getReader(); + $I->assertSame($expected, $actual); + + $expected = Reader::class; + $actual = $adapter->getReader(); + $I->assertInstanceOf($expected, $actual); + } +} diff --git a/tests/unit/Annotations/Adapter/Memory/ConstructCest.php b/tests/unit/Annotations/Adapter/Memory/ConstructCest.php deleted file mode 100644 index eaa23fde5f3..00000000000 --- a/tests/unit/Annotations/Adapter/Memory/ConstructCest.php +++ /dev/null @@ -1,39 +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\Memory; - -use Phalcon\Annotations\Adapter\AdapterInterface; -use Phalcon\Annotations\Adapter\Memory; -use UnitTester; - -class ConstructCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Memory :: __construct() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterMemoryConstruct(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Memory - __construct()'); - - $oAdapter = new Memory(); - - $I->assertInstanceOf( - AdapterInterface::class, - $oAdapter - ); - } -} diff --git a/tests/unit/Annotations/Adapter/Memory/GetCest.php b/tests/unit/Annotations/Adapter/Memory/GetCest.php deleted file mode 100644 index 7b53409fe2a..00000000000 --- a/tests/unit/Annotations/Adapter/Memory/GetCest.php +++ /dev/null @@ -1,54 +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\Memory; - -use Phalcon\Annotations\Adapter\Memory; -use Phalcon\Annotations\Collection; -use Phalcon\Annotations\Reflection; -use TestClass; -use UnitTester; - -class GetCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Memory :: get() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterMemoryGet(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Memory - get()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $oAdapter = new Memory(); - - $oClassAnnotations = $oAdapter->get( - TestClass::class - ); - - $I->assertTrue(is_object($oClassAnnotations)); - - $I->assertInstanceOf( - Reflection::class, - $oClassAnnotations - ); - - $I->assertInstanceOf( - Collection::class, - $oClassAnnotations->getClassAnnotations() - ); - } -} diff --git a/tests/unit/Annotations/Adapter/Memory/GetMethodCest.php b/tests/unit/Annotations/Adapter/Memory/GetMethodCest.php deleted file mode 100644 index 0b56516682b..00000000000 --- a/tests/unit/Annotations/Adapter/Memory/GetMethodCest.php +++ /dev/null @@ -1,49 +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\Memory; - -use Phalcon\Annotations\Adapter\Memory; -use Phalcon\Annotations\Collection; -use TestClass; -use UnitTester; - -use function dataDir; - -class GetMethodCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Memory :: getMethod() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterMemoryGetMethod(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Memory - getMethod()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $oAdapter = new Memory(); - - $sMethodAnnotation = $oAdapter->getMethod( - TestClass::class, - 'testMethod1' - ); - - $I->assertInstanceOf( - Collection::class, - $sMethodAnnotation - ); - } -} diff --git a/tests/unit/Annotations/Adapter/Memory/GetMethodsCest.php b/tests/unit/Annotations/Adapter/Memory/GetMethodsCest.php deleted file mode 100644 index 5a0592f98f0..00000000000 --- a/tests/unit/Annotations/Adapter/Memory/GetMethodsCest.php +++ /dev/null @@ -1,61 +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\Memory; - -use Phalcon\Annotations\Adapter\Memory; -use Phalcon\Annotations\Collection; -use TestClass; -use UnitTester; - -use function dataDir; - -class GetMethodsCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Memory :: getMethods() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterMemoryGetMethods(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Memory - getMethods()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $oAdapter = new Memory(); - - $aMethodAnnotations = $oAdapter->getMethods( - TestClass::class - ); - - $aKeys = array_keys($aMethodAnnotations); - $I->assertEquals( - [ - 'testMethod1', - 'testMethod3', - 'testMethod4', - 'testMethod5', - ], - $aKeys - ); - - foreach ($aMethodAnnotations as $oMethodAnnotation) { - $I->assertInstanceOf( - Collection::class, - $oMethodAnnotation - ); - } - } -} diff --git a/tests/unit/Annotations/Adapter/Memory/GetPropertiesCest.php b/tests/unit/Annotations/Adapter/Memory/GetPropertiesCest.php deleted file mode 100644 index 88939c14b9e..00000000000 --- a/tests/unit/Annotations/Adapter/Memory/GetPropertiesCest.php +++ /dev/null @@ -1,60 +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\Memory; - -use Phalcon\Annotations\Adapter\Memory; -use Phalcon\Annotations\Collection; -use TestClass; -use UnitTester; - -use function dataDir; - -class GetPropertiesCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Memory :: getProperties() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterMemoryGetProperties(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Memory - getProperties()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $oAdapter = new Memory(); - - $aPropertyAnnotations = $oAdapter->getProperties( - TestClass::class - ); - - $aKeys = array_keys($aPropertyAnnotations); - $I->assertEquals( - [ - 'testProp1', - 'testProp3', - 'testProp4', - ], - $aKeys - ); - - foreach ($aPropertyAnnotations as $oPropertyAnnotation) { - $I->assertInstanceOf( - Collection::class, - $oPropertyAnnotation - ); - } - } -} diff --git a/tests/unit/Annotations/Adapter/Memory/GetPropertyCest.php b/tests/unit/Annotations/Adapter/Memory/GetPropertyCest.php deleted file mode 100644 index 0944cc1bce2..00000000000 --- a/tests/unit/Annotations/Adapter/Memory/GetPropertyCest.php +++ /dev/null @@ -1,47 +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\Memory; - -use Phalcon\Annotations\Adapter\Memory; -use Phalcon\Annotations\Collection; -use TestClass; -use UnitTester; - -class GetPropertyCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Memory :: getProperty() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterMemoryGetProperty(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Memory - getProperty()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $oAdapter = new Memory(); - - $oPropertyAnnotations = $oAdapter->getProperty( - TestClass::class, - 'testProp1' - ); - - $I->assertInstanceOf( - Collection::class, - $oPropertyAnnotations - ); - } -} diff --git a/tests/unit/Annotations/Adapter/Memory/GetSetReaderCest.php b/tests/unit/Annotations/Adapter/Memory/GetSetReaderCest.php deleted file mode 100644 index cb536e817c0..00000000000 --- a/tests/unit/Annotations/Adapter/Memory/GetSetReaderCest.php +++ /dev/null @@ -1,46 +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\Memory; - -use Phalcon\Annotations\Adapter\Memory; -use Phalcon\Annotations\Reader; -use UnitTester; - -class GetSetReaderCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Memory :: getReader() / setReader() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterMemoryGetSetReader(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Memory - getReader() / setReader()'); - - $oAdapter = new Memory(); - - $oReader = new Reader(); - $oAdapter->setReader($oReader); - - $I->assertSame( - $oReader, - $oAdapter->getReader() - ); - - $oClass = Reader::class; - $oActual = $oAdapter->getReader(); - $I->assertInstanceOf($oClass, $oActual); - } -} diff --git a/tests/unit/Annotations/Adapter/Memory/ReadWriteCest.php b/tests/unit/Annotations/Adapter/Memory/ReadWriteCest.php deleted file mode 100644 index 62b1235dcfe..00000000000 --- a/tests/unit/Annotations/Adapter/Memory/ReadWriteCest.php +++ /dev/null @@ -1,52 +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\Memory; - -use Phalcon\Annotations\Adapter\Memory; -use Phalcon\Annotations\Reflection; -use TestClass; -use UnitTester; - -use function dataDir; - -class ReadWriteCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Memory :: read() / write() - * - * @author Phalcon Team - * @since 2018-11-13 - */ - public function annotationsAdapterMemoryReadWrite(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Memory - read() / write()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $oAdapter = new Memory(); - - $oClassAnnotations = $oAdapter->get( - TestClass::class - ); - - $oAdapter->write('testwrite', $oClassAnnotations); - - $oNewClass = $oAdapter->read('testwrite'); - - $I->assertInstanceOf( - Reflection::class, - $oNewClass - ); - } -} diff --git a/tests/unit/Annotations/Adapter/MemoryCest.php b/tests/unit/Annotations/Adapter/MemoryCest.php deleted file mode 100644 index 9c51c359a9c..00000000000 --- a/tests/unit/Annotations/Adapter/MemoryCest.php +++ /dev/null @@ -1,121 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE.txt - * file that was distributed with this source code. - */ - -namespace Phalcon\Tests\Unit\Annotations\Adapter; - -use Phalcon\Annotations\Adapter\Memory; -use Phalcon\Annotations\Collection; -use Phalcon\Annotations\Reflection; -use TestClass; -use UnitTester; -use User\TestClassNs; - -use function dataDir; - -class MemoryCest -{ - public function testMemoryAdapter(UnitTester $I) - { - $I->seeFileFound( - dataDir('fixtures/Annotations/TestClass.php') - ); - - $I->seeFileFound( - dataDir('fixtures/Annotations/TestClassNs.php') - ); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - require_once dataDir('fixtures/Annotations/TestClassNs.php'); - - $adapter = new Memory(); - - $classAnnotations = $adapter->get( - TestClass::class - ); - - $I->assertTrue(is_object($classAnnotations)); - - $I->assertInstanceOf( - Reflection::class, - $classAnnotations - ); - - $I->assertInstanceOf( - Collection::class, - $classAnnotations->getClassAnnotations() - ); - - $classAnnotations = $adapter->get( - TestClass::class - ); - - $I->assertTrue(is_object($classAnnotations)); - - $I->assertInstanceOf( - Reflection::class, - $classAnnotations - ); - - $I->assertInstanceOf( - Collection::class, - $classAnnotations->getClassAnnotations() - ); - - $classAnnotations = $adapter->get( - TestClassNs::class - ); - - $I->assertTrue(is_object($classAnnotations)); - - $I->assertInstanceOf( - Reflection::class, - $classAnnotations - ); - - $I->assertInstanceOf( - Collection::class, - $classAnnotations->getClassAnnotations() - ); - - $classAnnotations = $adapter->get( - TestClassNs::class - ); - - $I->assertTrue(is_object($classAnnotations)); - - $I->assertInstanceOf( - Reflection::class, - $classAnnotations - ); - - $I->assertInstanceOf( - Collection::class, - $classAnnotations->getClassAnnotations() - ); - - $property = $adapter->getProperty( - TestClass::class, - 'testProp1' - ); - - $I->assertTrue(is_object($property)); - - $I->assertInstanceOf( - Collection::class, - $property - ); - - $I->assertEquals( - 4, - $property->count() - ); - } -} diff --git a/tests/unit/Annotations/Adapter/ReadWriteCest.php b/tests/unit/Annotations/Adapter/ReadWriteCest.php new file mode 100644 index 00000000000..f79436b832e --- /dev/null +++ b/tests/unit/Annotations/Adapter/ReadWriteCest.php @@ -0,0 +1,63 @@ + + * + * 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/Stream/ConstructCest.php b/tests/unit/Annotations/Adapter/Stream/ConstructCest.php deleted file mode 100644 index b7ba7fffb07..00000000000 --- a/tests/unit/Annotations/Adapter/Stream/ConstructCest.php +++ /dev/null @@ -1,45 +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\Stream; - -use Phalcon\Annotations\Adapter\AdapterInterface; -use Phalcon\Annotations\Adapter\Stream; -use UnitTester; - -use function outputDir; - -class ConstructCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Stream :: __construct() - * - * @author Phalcon Team - * @since 2018-11-13 - */ - public function annotationsAdapterStreamConstruct(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Stream - __construct()'); - - $adapter = new Stream( - [ - 'annotationsDir' => outputDir('tests/annotations/'), - ] - ); - - $I->assertInstanceOf( - AdapterInterface::class, - $adapter - ); - } -} diff --git a/tests/unit/Annotations/Adapter/Stream/GetCest.php b/tests/unit/Annotations/Adapter/Stream/GetCest.php deleted file mode 100644 index c2018924673..00000000000 --- a/tests/unit/Annotations/Adapter/Stream/GetCest.php +++ /dev/null @@ -1,64 +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\Stream; - -use Phalcon\Annotations\Adapter\Stream; -use Phalcon\Annotations\Collection; -use Phalcon\Annotations\Reflection; -use TestClass; -use UnitTester; - -use function dataDir; -use function outputDir; - -class GetCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Stream :: get() - * - * @author Phalcon Team - * @since 2018-11-13 - */ - public function annotationsAdapterStreamGet(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Stream - get()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $adapter = new Stream( - [ - 'annotationsDir' => outputDir('tests/annotations/'), - ] - ); - - - $classAnnotations = $adapter->get( - TestClass::class - ); - - $I->assertTrue(is_object($classAnnotations)); - - $I->assertInstanceOf( - Reflection::class, - $classAnnotations - ); - - $I->assertInstanceOf( - Collection::class, - $classAnnotations->getClassAnnotations() - ); - - $I->safeDeleteFile('testclass.php'); - } -} diff --git a/tests/unit/Annotations/Adapter/Stream/GetMethodCest.php b/tests/unit/Annotations/Adapter/Stream/GetMethodCest.php deleted file mode 100644 index 348870ddcbe..00000000000 --- a/tests/unit/Annotations/Adapter/Stream/GetMethodCest.php +++ /dev/null @@ -1,56 +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\Stream; - -use Phalcon\Annotations\Adapter\Stream; -use Phalcon\Annotations\Collection; -use TestClass; -use UnitTester; - -use function dataDir; -use function outputDir; - -class GetMethodCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Stream :: getMethod() - * - * @author Phalcon Team - * @since 2018-11-13 - */ - public function annotationsAdapterStreamGetMethod(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Stream - getMethod()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $adapter = new Stream( - [ - 'annotationsDir' => outputDir('tests/annotations/'), - ] - ); - - $methodAnnotation = $adapter->getMethod( - TestClass::class, - 'testMethod1' - ); - - $I->assertInstanceOf( - Collection::class, - $methodAnnotation - ); - - $I->safeDeleteFile('testclass.php'); - } -} diff --git a/tests/unit/Annotations/Adapter/Stream/GetMethodsCest.php b/tests/unit/Annotations/Adapter/Stream/GetMethodsCest.php deleted file mode 100644 index 01c9b3aa77a..00000000000 --- a/tests/unit/Annotations/Adapter/Stream/GetMethodsCest.php +++ /dev/null @@ -1,69 +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\Stream; - -use Phalcon\Annotations\Adapter\Stream; -use Phalcon\Annotations\Collection; -use TestClass; -use UnitTester; - -use function array_keys; -use function dataDir; -use function outputDir; - -class GetMethodsCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Stream :: getMethods() - * - * @author Phalcon Team - * @since 2018-11-13 - */ - public function annotationsAdapterStreamGetMethods(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Stream - getMethods()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $adapter = new Stream( - [ - 'annotationsDir' => outputDir('tests/annotations/'), - ] - ); - - $methodAnnotations = $adapter->getMethods( - TestClass::class - ); - - $keys = array_keys($methodAnnotations); - $I->assertEquals( - [ - 'testMethod1', - 'testMethod3', - 'testMethod4', - 'testMethod5', - ], - $keys - ); - - foreach ($methodAnnotations as $key => $methodAnnotation) { - $I->assertInstanceOf( - Collection::class, - $methodAnnotation - ); - } - - $I->safeDeleteFile('testclass.php'); - } -} diff --git a/tests/unit/Annotations/Adapter/Stream/GetPropertiesCest.php b/tests/unit/Annotations/Adapter/Stream/GetPropertiesCest.php deleted file mode 100644 index c0562a475f9..00000000000 --- a/tests/unit/Annotations/Adapter/Stream/GetPropertiesCest.php +++ /dev/null @@ -1,68 +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\Stream; - -use Phalcon\Annotations\Adapter\Stream; -use Phalcon\Annotations\Collection; -use TestClass; -use UnitTester; - -use function array_keys; -use function dataDir; -use function outputDir; - -class GetPropertiesCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Stream :: getProperties() - * - * @author Phalcon Team - * @since 2018-11-13 - */ - public function annotationsAdapterStreamGetProperties(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Stream - getProperties()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $adapter = new Stream( - [ - 'annotationsDir' => outputDir('tests/annotations/'), - ] - ); - - $propertyAnnotations = $adapter->getProperties( - TestClass::class - ); - - $keys = array_keys($propertyAnnotations); - $I->assertEquals( - [ - 'testProp1', - 'testProp3', - 'testProp4', - ], - $keys - ); - - foreach ($propertyAnnotations as $key => $propertyAnnotation) { - $I->assertInstanceOf( - Collection::class, - $propertyAnnotation - ); - } - - $I->safeDeleteFile('testclass.php'); - } -} diff --git a/tests/unit/Annotations/Adapter/Stream/GetPropertyCest.php b/tests/unit/Annotations/Adapter/Stream/GetPropertyCest.php deleted file mode 100644 index a1e62011dbf..00000000000 --- a/tests/unit/Annotations/Adapter/Stream/GetPropertyCest.php +++ /dev/null @@ -1,56 +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\Stream; - -use Phalcon\Annotations\Adapter\Stream; -use Phalcon\Annotations\Collection; -use TestClass; -use UnitTester; - -use function dataDir; -use function outputDir; - -class GetPropertyCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Stream :: getProperty() - * - * @author Phalcon Team - * @since 2018-11-13 - */ - public function annotationsAdapterStreamGetProperty(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Stream - getProperty()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $adapter = new Stream( - [ - 'annotationsDir' => outputDir('tests/annotations/'), - ] - ); - - $propertyAnnotation = $adapter->getProperty( - TestClass::class, - 'testProp1' - ); - - $I->assertInstanceOf( - Collection::class, - $propertyAnnotation - ); - - $I->safeDeleteFile('testclass.php'); - } -} diff --git a/tests/unit/Annotations/Adapter/Stream/GetSetReaderCest.php b/tests/unit/Annotations/Adapter/Stream/GetSetReaderCest.php deleted file mode 100644 index e1b92f649f7..00000000000 --- a/tests/unit/Annotations/Adapter/Stream/GetSetReaderCest.php +++ /dev/null @@ -1,50 +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\Stream; - -use Phalcon\Annotations\Adapter\Stream; -use Phalcon\Annotations\Reader; -use UnitTester; - -class GetSetReaderCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Stream :: getReader() / setReader() - * - * @author Jeremy PASTOURET - * @since 2020-01-22 - */ - public function annotationsAdapterStreamGetSetReader(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Stream - getReader() / setReader()'); - - $oAdapter = new Stream( - [ - 'annotationsDir' => outputDir('tests/annotations/'), - ] - ); - - $oReader = new Reader(); - $oAdapter->setReader($oReader); - - $I->assertSame( - $oReader, - $oAdapter->getReader() - ); - - $oClass = Reader::class; - $oActual = $oAdapter->getReader(); - $I->assertInstanceOf($oClass, $oActual); - } -} diff --git a/tests/unit/Annotations/Adapter/Stream/ReadCest.php b/tests/unit/Annotations/Adapter/Stream/ReadCest.php deleted file mode 100644 index a485c8f2e62..00000000000 --- a/tests/unit/Annotations/Adapter/Stream/ReadCest.php +++ /dev/null @@ -1,64 +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\Stream; - -use Phalcon\Annotations\Adapter\Stream; -use Phalcon\Annotations\Reflection; -use TestClass; -use UnitTester; - -use function dataDir; -use function outputDir; - -class ReadCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Stream :: read() - * - * @author Phalcon Team - * @since 2018-11-13 - */ - public function annotationsAdapterStreamRead(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Stream - read()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $adapter = new Stream( - [ - 'annotationsDir' => outputDir('tests/annotations/'), - ] - ); - - - $classAnnotations = $adapter->get( - TestClass::class - ); - - $adapter->write('testwrite', $classAnnotations); - - $I->assertFileExists( - outputDir('tests/annotations/testclass.php') - ); - - $newClass = $adapter->read('testwrite'); - $I->assertInstanceOf( - Reflection::class, - $newClass - ); - - $I->safeDeleteFile('testwrite.php'); - $I->safeDeleteFile('testclass.php'); - } -} diff --git a/tests/unit/Annotations/Adapter/Stream/WriteCest.php b/tests/unit/Annotations/Adapter/Stream/WriteCest.php deleted file mode 100644 index 16353471c77..00000000000 --- a/tests/unit/Annotations/Adapter/Stream/WriteCest.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\Stream; - -use Phalcon\Annotations\Adapter\Stream; -use TestClass; -use UnitTester; - -use function dataDir; -use function outputDir; - -class WriteCest -{ - /** - * Tests Phalcon\Annotations\Adapter\Stream :: write() - * - * @author Phalcon Team - * @since 2018-11-13 - */ - public function annotationsAdapterStreamWrite(UnitTester $I) - { - $I->wantToTest('Annotations\Adapter\Stream - write()'); - - require_once dataDir('fixtures/Annotations/TestClass.php'); - - $adapter = new Stream( - [ - 'annotationsDir' => outputDir('tests/annotations/'), - ] - ); - - - $classAnnotations = $adapter->get( - TestClass::class - ); - - $adapter->write('testwrite', $classAnnotations); - - $I->assertFileExists( - outputDir('tests/annotations/testclass.php') - ); - - $I->safeDeleteFile('testwrite.php'); - $I->safeDeleteFile('testclass.php'); - } -} diff --git a/tests/unit/Annotations/Annotation/GetArgumentCest.php b/tests/unit/Annotations/Annotation/GetArgumentCest.php index a5be21379d5..d14dd4d4a11 100644 --- a/tests/unit/Annotations/Annotation/GetArgumentCest.php +++ b/tests/unit/Annotations/Annotation/GetArgumentCest.php @@ -51,8 +51,8 @@ public function annotationsAnnotationGetArgument(UnitTester $I) ], ]); - $I->assertEquals($annotation->getArgument(0), $value); + $I->assertSame($annotation->getArgument(0), $value); - $I->assertEquals($annotation->getArgument(1), $value1); + $I->assertSame($annotation->getArgument(1), $value1); } } diff --git a/tests/unit/Annotations/Annotation/GetArgumentsCest.php b/tests/unit/Annotations/Annotation/GetArgumentsCest.php index 0a920cd190d..d1bbc8007da 100644 --- a/tests/unit/Annotations/Annotation/GetArgumentsCest.php +++ b/tests/unit/Annotations/Annotation/GetArgumentsCest.php @@ -51,6 +51,6 @@ public function annotationsAnnotationGetArguments(UnitTester $I) ], ]); - $I->assertEquals([$value, $value1], $annotation->getArguments()); + $I->assertSame([$value, $value1], $annotation->getArguments()); } } diff --git a/tests/unit/Annotations/Annotation/GetExprArgumentsCest.php b/tests/unit/Annotations/Annotation/GetExprArgumentsCest.php index ec780e600b3..589f37d5739 100644 --- a/tests/unit/Annotations/Annotation/GetExprArgumentsCest.php +++ b/tests/unit/Annotations/Annotation/GetExprArgumentsCest.php @@ -53,6 +53,6 @@ public function annotationsAnnotationGetExprArguments(UnitTester $I) 'arguments' => $expr, ]); - $I->assertEquals($annotation->getExprArguments(), $expr); + $I->assertSame($annotation->getExprArguments(), $expr); } } diff --git a/tests/unit/Annotations/Annotation/GetExpressionCest.php b/tests/unit/Annotations/Annotation/GetExpressionCest.php index d8333e12e97..692f8707f38 100644 --- a/tests/unit/Annotations/Annotation/GetExpressionCest.php +++ b/tests/unit/Annotations/Annotation/GetExpressionCest.php @@ -57,7 +57,7 @@ public function annotationsAnnotationGetExpression(UnitTester $I) 'arguments' => $expr, ]); - $I->assertEquals($annotation->GetExpression($oneExpr), $value); - $I->assertEquals($annotation->GetExpression($twoExpr), $value1); + $I->assertSame($annotation->GetExpression($oneExpr), $value); + $I->assertSame($annotation->GetExpression($twoExpr), $value1); } } diff --git a/tests/unit/Annotations/Annotation/GetNameCest.php b/tests/unit/Annotations/Annotation/GetNameCest.php index 0b90e649561..b6ae8810b85 100644 --- a/tests/unit/Annotations/Annotation/GetNameCest.php +++ b/tests/unit/Annotations/Annotation/GetNameCest.php @@ -34,6 +34,6 @@ public function annotationsAnnotationGetName(UnitTester $I) 'name' => 'NovAnnotation', ]); - $I->assertEquals($annotation->getName(), $name); + $I->assertSame($annotation->getName(), $name); } } diff --git a/tests/unit/Annotations/Annotation/GetNamedArgumentCest.php b/tests/unit/Annotations/Annotation/GetNamedArgumentCest.php index 9facbb51309..3bbe31bced3 100644 --- a/tests/unit/Annotations/Annotation/GetNamedArgumentCest.php +++ b/tests/unit/Annotations/Annotation/GetNamedArgumentCest.php @@ -96,12 +96,12 @@ public function annotationsAnnotationGetNamedArgument(UnitTester $I) $name1 => $value1, ]; - $I->assertEquals($annotation->getNamedArgument($exprName), $result); + $I->assertSame($annotation->getNamedArgument($exprName), $result); $result1 = [ $name2 => $value2, ]; - $I->assertEquals($annotation->getNamedArgument($exprName1), $result1); + $I->assertSame($annotation->getNamedArgument($exprName1), $result1); } } diff --git a/tests/unit/Annotations/Annotation/GetNamedParameterCest.php b/tests/unit/Annotations/Annotation/GetNamedParameterCest.php index b207574c029..dff1544fdf3 100644 --- a/tests/unit/Annotations/Annotation/GetNamedParameterCest.php +++ b/tests/unit/Annotations/Annotation/GetNamedParameterCest.php @@ -96,12 +96,12 @@ public function annotationsAnnotationGetNamedParameter(UnitTester $I) $name1 => $value1, ]; - $I->assertEquals($annotation->getNamedParameter($exprName), $result); + $I->assertSame($annotation->getNamedParameter($exprName), $result); $result1 = [ $name2 => $value2, ]; - $I->assertEquals($annotation->getNamedParameter($exprName1), $result1); + $I->assertSame($annotation->getNamedParameter($exprName1), $result1); } } diff --git a/tests/unit/Annotations/Annotation/NumberArgumentsCest.php b/tests/unit/Annotations/Annotation/NumberArgumentsCest.php index b4421549a6f..f0afc047f18 100644 --- a/tests/unit/Annotations/Annotation/NumberArgumentsCest.php +++ b/tests/unit/Annotations/Annotation/NumberArgumentsCest.php @@ -51,6 +51,6 @@ public function annotationsAnnotationNumberArguments(UnitTester $I) ], ]); - $I->assertEquals($annotation->numberArguments(), 2); + $I->assertSame($annotation->numberArguments(), 2); } } diff --git a/tests/unit/Annotations/Collection/ConstructCest.php b/tests/unit/Annotations/Collection/ConstructCest.php index 17ade806b72..b49caf9d6c4 100644 --- a/tests/unit/Annotations/Collection/ConstructCest.php +++ b/tests/unit/Annotations/Collection/ConstructCest.php @@ -30,10 +30,9 @@ public function annotationsCollectionConstruct(UnitTester $I) $collection = new Collection(); - $I->assertInstanceOf( - Collection::class, - $collection - ); + $expected = Collection::class; + $actual = $collection; + $I->assertInstanceOf($expected, $actual); } /** @@ -55,9 +54,8 @@ public function annotationsCollectionConstructWithArrayParam(UnitTester $I) ] ); - $I->assertInstanceOf( - Collection::class, - $collection - ); + $expected = Collection::class; + $actual = $collection; + $I->assertInstanceOf($expected, $actual); } } diff --git a/tests/unit/Annotations/Collection/CountCest.php b/tests/unit/Annotations/Collection/CountCest.php index 860483699a4..6be32b3736f 100644 --- a/tests/unit/Annotations/Collection/CountCest.php +++ b/tests/unit/Annotations/Collection/CountCest.php @@ -39,6 +39,8 @@ public function annotationsCollectionCount(UnitTester $I) $collection = new Collection($reflectionData); - $I->assertEquals(count($reflectionData), $collection->count()); + $expected = count($reflectionData); + $actual = $collection->count(); + $I->assertSame($expected, $actual); } } diff --git a/tests/unit/Annotations/Collection/GetAllCest.php b/tests/unit/Annotations/Collection/GetAllCest.php index cacf505c455..3abf876111a 100644 --- a/tests/unit/Annotations/Collection/GetAllCest.php +++ b/tests/unit/Annotations/Collection/GetAllCest.php @@ -57,10 +57,13 @@ public function annotationsCollectionGetAll(UnitTester $I) $annotation2, ]; - //Check the result if the annotation doesn't exist - $I->assertEmpty($collection->getAll('Phalconatation')); + // Check the result if the annotation doesn't exist + $actual = $collection->getAll('Phalconatation'); + $I->assertEmpty($actual); - //Need to find two annotations with the name NovAnnotation - $I->assertEquals($resultAnnotation, $collection->getAll('NovAnnotation')); + // Need to find two annotations with the name NovAnnotation + $expected = $resultAnnotation; + $actual = $collection->getAll('NovAnnotation'); + $I->assertEquals($expected, $actual); } } diff --git a/tests/unit/Annotations/Collection/GetAnnotationsCest.php b/tests/unit/Annotations/Collection/GetAnnotationsCest.php index 409de595e22..2270cc10e98 100644 --- a/tests/unit/Annotations/Collection/GetAnnotationsCest.php +++ b/tests/unit/Annotations/Collection/GetAnnotationsCest.php @@ -59,7 +59,9 @@ public function annotationsCollectionGetAnnotations(UnitTester $I) $annotation2, ]; - //Need to find two annotations with the name NovAnnotation - $I->assertEquals($resultAnnotation, $collection->getAnnotations()); + // Need to find two annotations with the name NovAnnotation + $expected = $resultAnnotation; + $actual = $collection->getAnnotations(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/unit/Annotations/Collection/GetCest.php b/tests/unit/Annotations/Collection/GetCest.php index 32fd07b4429..f1f98b4d36e 100644 --- a/tests/unit/Annotations/Collection/GetCest.php +++ b/tests/unit/Annotations/Collection/GetCest.php @@ -46,11 +46,13 @@ public function annotationsCollectionGet(UnitTester $I) $collection = new Collection($reflectionData); $annotation = new Annotation($dataAnnotation1); - $I->assertEquals($annotation, $collection->get('Phalconatation')); + $expected = $annotation; + $actual = $collection->get('Phalconatation'); + $I->assertEquals($expected, $actual); //Check what happens if collection doesn't find an annotation $I->expectThrowable( - new Exception('Collection doesn\'t have an annotation called \'NoExist\''), + new Exception("Collection does not have an annotation called 'NoExist'"), function () { $collection = new Collection(); $collection->get('NoExist'); diff --git a/tests/unit/Annotations/Collection/HasCest.php b/tests/unit/Annotations/Collection/HasCest.php index 4b0906ea839..7f6a97d5643 100644 --- a/tests/unit/Annotations/Collection/HasCest.php +++ b/tests/unit/Annotations/Collection/HasCest.php @@ -43,8 +43,10 @@ public function annotationsCollectionHas(UnitTester $I) $collection = new Collection($reflectionData); - $I->assertTrue($collection->has('Phalconatation')); + $actual = $collection->has('Phalconatation'); + $I->assertTrue($actual); - $I->assertFalse($collection->has('Phalcony')); + $actual = $collection->has('Phalcony'); + $I->assertFalse($actual); } } diff --git a/tests/unit/Annotations/Collection/KeyNextRewindCest.php b/tests/unit/Annotations/Collection/KeyNextRewindCest.php index df5396d4c9a..6c286a85213 100644 --- a/tests/unit/Annotations/Collection/KeyNextRewindCest.php +++ b/tests/unit/Annotations/Collection/KeyNextRewindCest.php @@ -46,20 +46,32 @@ public function annotationsCollectionKeyNextRewind(UnitTester $I) $annotation = new Annotation($dataAnnotation); $annotation1 = new Annotation($dataAnnotation1); - $I->assertEquals(0, $collection->key()); + $expected = 0; + $actual = $collection->key(); + $I->assertSame($expected, $actual); - $I->assertEquals($annotation, $collection->current()); + $expected = $annotation; + $actual = $collection->current(); + $I->assertEquals($expected, $actual); $collection->next(); - $I->assertEquals(1, $collection->key()); + $expected = 1; + $actual = $collection->key(); - $I->assertEquals($annotation1, $collection->current()); + $I->assertSame($expected, $actual); + $expected = $annotation1; + $actual = $collection->current(); + $I->assertEquals($expected, $actual); $collection->rewind(); - $I->assertEquals(0, $collection->key()); + $expected = 0; + $actual = $collection->key(); + $I->assertSame($expected, $actual); - $I->assertEquals($annotation, $collection->current()); + $expected = $annotation; + $actual = $collection->current(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/unit/Annotations/Collection/ValidCest.php b/tests/unit/Annotations/Collection/ValidCest.php index e776dabae33..9995a31e5bc 100644 --- a/tests/unit/Annotations/Collection/ValidCest.php +++ b/tests/unit/Annotations/Collection/ValidCest.php @@ -13,7 +13,6 @@ namespace Phalcon\Tests\Unit\Annotations\Collection; -use Phalcon\Annotations\Annotation; use Phalcon\Annotations\Collection; use UnitTester; @@ -42,18 +41,19 @@ public function annotationsCollectionValid(UnitTester $I) $dataAnnotation1, ]; - $collection = new Collection($reflectionData); - $annotation = new Annotation($dataAnnotation); - $annotation1 = new Annotation($dataAnnotation1); + $collection = new Collection($reflectionData); - $I->assertTrue($collection->valid()); + $actual = $collection->valid(); + $I->assertTrue($actual); $collection->next(); - $I->assertTrue($collection->valid()); + $actual = $collection->valid(); + $I->assertTrue($actual); $collection->next(); - $I->assertFalse($collection->valid()); + $actual = $collection->valid(); + $I->assertFalse($actual); } } diff --git a/tests/unit/Annotations/Reader/ParseCest.php b/tests/unit/Annotations/Reader/ParseCest.php index 87e49793129..247749ba82f 100644 --- a/tests/unit/Annotations/Reader/ParseCest.php +++ b/tests/unit/Annotations/Reader/ParseCest.php @@ -99,175 +99,491 @@ public function testReaderParse(UnitTester $I) $reader = new Reader(); $parsing = $reader->parse('TestClass'); - $I->assertTrue( - isset($parsing['class']) - ); + $actual = isset($parsing['class']); + $I->assertTrue($actual); - $I->assertCount(9, $parsing['class']); + $expected = 9; + $actual = $parsing['class']; + $I->assertCount($expected, $actual); // Simple - $I->assertEquals('Simple', $parsing['class'][0]['name']); - $I->assertFalse(isset($parsing['class'][0]['arguments'])); + $expected = 'Simple'; + $actual = $parsing['class'][0]['name']; + $I->assertSame($expected, $actual); + + $actual = isset($parsing['class'][0]['arguments']); + $I->assertFalse($actual); // Single Param - $I->assertEquals('SingleParam', $parsing['class'][1]['name']); - $I->assertTrue(isset($parsing['class'][1]['arguments'])); - $I->assertCount(1, $parsing['class'][1]['arguments']); - $I->assertEquals('Param', $parsing['class'][1]['arguments'][0]['expr']['value']); + $expected = 'SingleParam'; + $actual = $parsing['class'][1]['name']; + $I->assertSame($expected, $actual); + + $actual = isset($parsing['class'][1]['arguments']); + $I->assertTrue($actual); + + $expected = 1; + $actual = $parsing['class'][1]['arguments']; + $I->assertCount($expected, $actual); + + $expected = 'Param'; + $actual = $parsing['class'][1]['arguments'][0]['expr']['value']; + $I->assertSame($expected, $actual); // Multiple Params - $I->assertEquals('MultipleParams', $parsing['class'][2]['name']); - $I->assertTrue(isset($parsing['class'][2]['arguments'])); - $I->assertCount(8, $parsing['class'][2]['arguments']); - $I->assertEquals('First', $parsing['class'][2]['arguments'][0]['expr']['value']); - $I->assertEquals('Second', $parsing['class'][2]['arguments'][1]['expr']['value']); - $I->assertEquals('1', $parsing['class'][2]['arguments'][2]['expr']['value']); - $I->assertEquals('1.1', $parsing['class'][2]['arguments'][3]['expr']['value']); - $I->assertEquals('-10', $parsing['class'][2]['arguments'][4]['expr']['value']); - $I->assertEquals(305, $parsing['class'][2]['arguments'][5]['expr']['type']); - $I->assertEquals(306, $parsing['class'][2]['arguments'][6]['expr']['type']); - $I->assertEquals(304, $parsing['class'][2]['arguments'][7]['expr']['type']); + $expected = 8; + $actual = $parsing['class'][2]['arguments']; + $I->assertCount($expected, $actual); + + $actual = isset($parsing['class'][2]['arguments']); + $I->assertTrue($actual); + + $expected = 'MultipleParams'; + $actual = $parsing['class'][2]['name']; + $I->assertSame($expected, $actual); + + $expected = 'First'; + $actual = $parsing['class'][2]['arguments'][0]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = 'Second'; + $actual = $parsing['class'][2]['arguments'][1]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = '1'; + $actual = $parsing['class'][2]['arguments'][2]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = '1.1'; + $actual = $parsing['class'][2]['arguments'][3]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = '-10'; + $actual = $parsing['class'][2]['arguments'][4]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = 305; + $actual = $parsing['class'][2]['arguments'][5]['expr']['type']; + $I->assertSame($expected, $actual); + + $expected = 306; + $actual = $parsing['class'][2]['arguments'][6]['expr']['type']; + $I->assertSame($expected, $actual); + + $expected = 304; + $actual = $parsing['class'][2]['arguments'][7]['expr']['type']; + $I->assertSame($expected, $actual); + // Single Array Param - $I->assertEquals('Params', $parsing['class'][3]['name']); - $I->assertTrue(isset($parsing['class'][3]['arguments'])); - $I->assertCount(1, $parsing['class'][3]['arguments']); - $I->assertEquals(308, $parsing['class'][3]['arguments'][0]['expr']['type']); - $I->assertCount(3, $parsing['class'][3]['arguments'][0]['expr']['items']); - $I->assertEquals('key1', $parsing['class'][3]['arguments'][0]['expr']['items'][0]['expr']['value']); - $I->assertEquals('key2', $parsing['class'][3]['arguments'][0]['expr']['items'][1]['expr']['value']); - $I->assertEquals('key3', $parsing['class'][3]['arguments'][0]['expr']['items'][2]['expr']['value']); + $expected = 1; + $actual = $parsing['class'][3]['arguments']; + $I->assertCount($expected, $actual); + + $expected = 3; + $actual = $parsing['class'][3]['arguments'][0]['expr']['items']; + $I->assertCount($expected, $actual); + + $actual = isset($parsing['class'][3]['arguments']); + $I->assertTrue($actual); + + $expected = 'Params'; + $actual = $parsing['class'][3]['name']; + $I->assertSame($expected, $actual); + + $expected = 308; + $actual = $parsing['class'][3]['arguments'][0]['expr']['type']; + $I->assertSame($expected, $actual); + + $expected = 'key1'; + $actual = $parsing['class'][3]['arguments'][0]['expr']['items'][0]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = 'key2'; + $actual = $parsing['class'][3]['arguments'][0]['expr']['items'][1]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = 'key3'; + $actual = $parsing['class'][3]['arguments'][0]['expr']['items'][2]['expr']['value']; + $I->assertSame($expected, $actual); + // Hash Params - $I->assertEquals('HashParams', $parsing['class'][4]['name']); - $I->assertTrue(isset($parsing['class'][4]['arguments'])); - $I->assertCount(1, $parsing['class'][8]['arguments']); - $I->assertEquals(308, $parsing['class'][4]['arguments'][0]['expr']['type']); - $I->assertCount(3, $parsing['class'][4]['arguments'][0]['expr']['items']); - $I->assertEquals('key1', $parsing['class'][4]['arguments'][0]['expr']['items'][0]['name']); - $I->assertEquals('value', $parsing['class'][4]['arguments'][0]['expr']['items'][0]['expr']['value']); - $I->assertEquals('key2', $parsing['class'][4]['arguments'][0]['expr']['items'][1]['name']); - $I->assertEquals('value', $parsing['class'][4]['arguments'][0]['expr']['items'][1]['expr']['value']); - $I->assertEquals('key3', $parsing['class'][4]['arguments'][0]['expr']['items'][2]['name']); - $I->assertEquals('value', $parsing['class'][4]['arguments'][0]['expr']['items'][2]['expr']['value']); + $expected = 1; + $actual = $parsing['class'][8]['arguments']; + $I->assertCount($expected, $actual); + + $expected = 3; + $actual = $parsing['class'][4]['arguments'][0]['expr']['items']; + $I->assertCount($expected, $actual); + + $actual = isset($parsing['class'][4]['arguments']); + $I->assertTrue($actual); + + $expected = 'HashParams'; + $actual = $parsing['class'][4]['name']; + $I->assertSame($expected, $actual); + + $expected = 308; + $actual = $parsing['class'][4]['arguments'][0]['expr']['type']; + $I->assertSame($expected, $actual); + + $expected = 'key1'; + $actual = $parsing['class'][4]['arguments'][0]['expr']['items'][0]['name']; + $I->assertSame($expected, $actual); + + $expected = 'value'; + $actual = $parsing['class'][4]['arguments'][0]['expr']['items'][0]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = 'key2'; + $actual = $parsing['class'][4]['arguments'][0]['expr']['items'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'value'; + $actual = $parsing['class'][4]['arguments'][0]['expr']['items'][1]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = 'key3'; + $actual = $parsing['class'][4]['arguments'][0]['expr']['items'][2]['name']; + $I->assertSame($expected, $actual); + + $expected = 'value'; + $actual = $parsing['class'][4]['arguments'][0]['expr']['items'][2]['expr']['value']; + $I->assertSame($expected, $actual); + // Named Params - $I->assertEquals('NamedParams', $parsing['class'][5]['name']); - $I->assertTrue(isset($parsing['class'][5]['arguments'])); - $I->assertCount(2, $parsing['class'][5]['arguments']); - $I->assertEquals('second', $parsing['class'][5]['arguments'][1]['name']); - $I->assertEquals('other', $parsing['class'][5]['arguments'][1]['expr']['value']); - $I->assertEquals('second', $parsing['class'][5]['arguments'][1]['name']); - $I->assertEquals('other', $parsing['class'][5]['arguments'][1]['expr']['value']); + $expected = 2; + $actual = $parsing['class'][5]['arguments']; + $I->assertCount($expected, $actual); + + $actual = isset($parsing['class'][5]['arguments']); + $I->assertTrue($actual); + + $expected = 'NamedParams'; + $actual = $parsing['class'][5]['name']; + $I->assertSame($expected, $actual); + + $expected = 'second'; + $actual = $parsing['class'][5]['arguments'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'other'; + $actual = $parsing['class'][5]['arguments'][1]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = 'second'; + $actual = $parsing['class'][5]['arguments'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'other'; + $actual = $parsing['class'][5]['arguments'][1]['expr']['value']; + $I->assertSame($expected, $actual); + // Alternative Named Params - $I->assertEquals('AlternativeNamedParams', $parsing['class'][6]['name']); - $I->assertTrue(isset($parsing['class'][6]['arguments'])); - $I->assertCount(2, $parsing['class'][6]['arguments']); - $I->assertEquals('second', $parsing['class'][6]['arguments'][1]['name']); - $I->assertEquals('other', $parsing['class'][6]['arguments'][1]['expr']['value']); - $I->assertEquals('second', $parsing['class'][6]['arguments'][1]['name']); - $I->assertEquals('other', $parsing['class'][6]['arguments'][1]['expr']['value']); + $expected = 2; + $actual = $parsing['class'][6]['arguments']; + $I->assertCount($expected, $actual); + + $actual = isset($parsing['class'][6]['arguments']); + $I->assertTrue($actual); + + $expected = 'AlternativeNamedParams'; + $actual = $parsing['class'][6]['name']; + $I->assertSame($expected, $actual); + + $expected = 'second'; + $actual = $parsing['class'][6]['arguments'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'other'; + $actual = $parsing['class'][6]['arguments'][1]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = 'second'; + $actual = $parsing['class'][6]['arguments'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'other'; + $actual = $parsing['class'][6]['arguments'][1]['expr']['value']; + $I->assertSame($expected, $actual); + // Alternative Hash Params - $I->assertEquals('AlternativeHashParams', $parsing['class'][7]['name']); - $I->assertTrue(isset($parsing['class'][7]['arguments'])); - $I->assertCount(1, $parsing['class'][7]['arguments']); - $I->assertEquals(308, $parsing['class'][7]['arguments'][0]['expr']['type']); - $I->assertCount(3, $parsing['class'][7]['arguments'][0]['expr']['items']); - $I->assertEquals('key1', $parsing['class'][7]['arguments'][0]['expr']['items'][0]['name']); - $I->assertEquals('value', $parsing['class'][7]['arguments'][0]['expr']['items'][0]['expr']['value']); - $I->assertEquals('key2', $parsing['class'][7]['arguments'][0]['expr']['items'][1]['name']); - $I->assertEquals('value', $parsing['class'][7]['arguments'][0]['expr']['items'][1]['expr']['value']); - $I->assertEquals('key3', $parsing['class'][7]['arguments'][0]['expr']['items'][2]['name']); - $I->assertEquals('value', $parsing['class'][7]['arguments'][0]['expr']['items'][2]['expr']['value']); + $expected = 1; + $actual = $parsing['class'][7]['arguments']; + $I->assertCount($expected, $actual); + + $expected = 3; + $actual = $parsing['class'][7]['arguments'][0]['expr']['items']; + $I->assertCount($expected, $actual); + + $actual = isset($parsing['class'][7]['arguments']); + $I->assertTrue($actual); + + $expected = 'AlternativeHashParams'; + $actual = $parsing['class'][7]['name']; + $I->assertSame($expected, $actual); + + $expected = 308; + $actual = $parsing['class'][7]['arguments'][0]['expr']['type']; + $I->assertSame($expected, $actual); + + $expected = 'key1'; + $actual = $parsing['class'][7]['arguments'][0]['expr']['items'][0]['name']; + $I->assertSame($expected, $actual); + + $expected = 'value'; + $actual = $parsing['class'][7]['arguments'][0]['expr']['items'][0]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = 'key2'; + $actual = $parsing['class'][7]['arguments'][0]['expr']['items'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'value'; + $actual = $parsing['class'][7]['arguments'][0]['expr']['items'][1]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = 'key3'; + $actual = $parsing['class'][7]['arguments'][0]['expr']['items'][2]['name']; + $I->assertSame($expected, $actual); + + $expected = 'value'; + $actual = $parsing['class'][7]['arguments'][0]['expr']['items'][2]['expr']['value']; + $I->assertSame($expected, $actual); // Recursive Hash - $I->assertEquals('RecursiveHash', $parsing['class'][8]['name']); - $I->assertTrue(isset($parsing['class'][8]['arguments'])); - $I->assertCount(1, $parsing['class'][8]['arguments']); - $I->assertEquals(308, $parsing['class'][8]['arguments'][0]['expr']['type']); - $I->assertCount(3, $parsing['class'][8]['arguments'][0]['expr']['items']); - $I->assertEquals('key1', $parsing['class'][8]['arguments'][0]['expr']['items'][0]['name']); - $I->assertEquals('value', $parsing['class'][8]['arguments'][0]['expr']['items'][0]['expr']['value']); - $I->assertEquals('key2', $parsing['class'][8]['arguments'][0]['expr']['items'][1]['name']); - $I->assertEquals('value', $parsing['class'][8]['arguments'][0]['expr']['items'][1]['expr']['value']); - $I->assertEquals('key3', $parsing['class'][8]['arguments'][0]['expr']['items'][2]['name']); - $I->assertEquals(308, $parsing['class'][8]['arguments'][0]['expr']['items'][2]['expr']['type']); + $expected = 1; + $actual = $parsing['class'][8]['arguments']; + $I->assertCount($expected, $actual); + + $expected = 3; + $actual = $parsing['class'][8]['arguments'][0]['expr']['items']; + $I->assertCount($expected, $actual); + + $actual = isset($parsing['class'][8]['arguments']); + $I->assertTrue($actual); + + $expected = 'RecursiveHash'; + $actual = $parsing['class'][8]['name']; + $I->assertSame($expected, $actual); + + $expected = 308; + $actual = $parsing['class'][8]['arguments'][0]['expr']['type']; + $I->assertSame($expected, $actual); + + $expected = 'key1'; + $actual = $parsing['class'][8]['arguments'][0]['expr']['items'][0]['name']; + $I->assertSame($expected, $actual); + + $expected = 'value'; + $actual = $parsing['class'][8]['arguments'][0]['expr']['items'][0]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = 'key2'; + $actual = $parsing['class'][8]['arguments'][0]['expr']['items'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'value'; + $actual = $parsing['class'][8]['arguments'][0]['expr']['items'][1]['expr']['value']; + $I->assertSame($expected, $actual); + + $expected = 'key3'; + $actual = $parsing['class'][8]['arguments'][0]['expr']['items'][2]['name']; + $I->assertSame($expected, $actual); + + $expected = 308; + $actual = $parsing['class'][8]['arguments'][0]['expr']['items'][2]['expr']['type']; + $I->assertSame($expected, $actual); + // Constants - $I->assertTrue(isset($parsing['constants'])); - $I->assertCount(1, $parsing['constants']); - $I->assertFalse(isset($parsing['constants']['TEST_CONST2'])); - $I->assertEquals('Simple', $parsing['constants']['TEST_CONST1'][0]['name']); + $expected = 1; + $actual = $parsing['constants']; + $I->assertCount($expected, $actual); + + $actual = isset($parsing['constants']); + $I->assertTrue($actual); + + $actual = isset($parsing['constants']['TEST_CONST2']); + $I->assertFalse($actual); + + $expected = 'Simple'; + $actual = $parsing['constants']['TEST_CONST1'][0]['name']; + $I->assertSame($expected, $actual); // Properties - $I->assertTrue(isset($parsing['properties'])); - $I->assertCount(3, $parsing['properties']); + $expected = 3; + $actual = $parsing['properties']; + $I->assertCount($expected, $actual); + + $actual = isset($parsing['properties']); + $I->assertTrue($actual); + + // Multiple well-ordered annotations + $expected = 4; + $actual = $parsing['properties']['testProp1']; + $I->assertCount($expected, $actual); + + $actual = isset($parsing['properties']['testProp1']); + $I->assertTrue($actual); + + $expected = 'var'; + $actual = $parsing['properties']['testProp1'][0]['name']; + $I->assertSame($expected, $actual); + + $expected = 'Simple'; + $actual = $parsing['properties']['testProp1'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'SingleParam'; + $actual = $parsing['properties']['testProp1'][2]['name']; + $I->assertSame($expected, $actual); - // Multiple well ordered annotations - $I->assertTrue(isset($parsing['properties']['testProp1'])); - $I->assertCount(4, $parsing['properties']['testProp1']); - $I->assertEquals('var', $parsing['properties']['testProp1'][0]['name']); - $I->assertEquals('Simple', $parsing['properties']['testProp1'][1]['name']); - $I->assertEquals('SingleParam', $parsing['properties']['testProp1'][2]['name']); - $I->assertEquals('MultipleParams', $parsing['properties']['testProp1'][3]['name']); + $expected = 'MultipleParams'; + $actual = $parsing['properties']['testProp1'][3]['name']; + $I->assertSame($expected, $actual); // Comment without content - $I->assertFalse(isset($parsing['properties']['testProp2'])); + $actual = isset($parsing['properties']['testProp2']); + $I->assertFalse($actual); // Same line annotations - $I->assertCount(3, $parsing['properties']['testProp3']); - $I->assertEquals('Simple', $parsing['properties']['testProp3'][0]['name']); - $I->assertEquals('SingleParam', $parsing['properties']['testProp3'][1]['name']); - $I->assertEquals('MultipleParams', $parsing['properties']['testProp3'][2]['name']); + $expected = 3; + $actual = $parsing['properties']['testProp3']; + $I->assertCount($expected, $actual); + + $expected = 'Simple'; + $actual = $parsing['properties']['testProp3'][0]['name']; + $I->assertSame($expected, $actual); + + $expected = 'SingleParam'; + $actual = $parsing['properties']['testProp3'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'MultipleParams'; + $actual = $parsing['properties']['testProp3'][2]['name']; + $I->assertSame($expected, $actual); // Same line annotations - $I->assertCount(3, $parsing['properties']['testProp4']); - $I->assertEquals('Simple', $parsing['properties']['testProp4'][0]['name']); - $I->assertEquals('SingleParam', $parsing['properties']['testProp4'][1]['name']); - $I->assertEquals('MultipleParams', $parsing['properties']['testProp4'][2]['name']); + $expected = 3; + $actual = $parsing['properties']['testProp4']; + $I->assertCount($expected, $actual); + + $expected = 'Simple'; + $actual = $parsing['properties']['testProp4'][0]['name']; + $I->assertSame($expected, $actual); + + $expected = 'SingleParam'; + $actual = $parsing['properties']['testProp4'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'MultipleParams'; + $actual = $parsing['properties']['testProp4'][2]['name']; + $I->assertSame($expected, $actual); + // No docblock - $I->assertFalse(isset($parsing['properties']['testMethod5'])); + $actual = isset($parsing['properties']['testMethod5']); + $I->assertFalse($actual); // No annotations - $I->assertFalse(isset($parsing['properties']['testMethod6'])); + $actual = isset($parsing['properties']['testMethod6']); + $I->assertFalse($actual); // Properties - $I->assertTrue(isset($parsing['methods'])); - $I->assertCount(4, $parsing['methods']); - - // Multiple well ordered annotations - $I->assertTrue(isset($parsing['methods']['testMethod1'])); - $I->assertCount(5, $parsing['methods']['testMethod1']); - $I->assertEquals('return', $parsing['methods']['testMethod1'][0]['name']); - $I->assertEquals('Simple', $parsing['methods']['testMethod1'][1]['name']); - $I->assertEquals('SingleParam', $parsing['methods']['testMethod1'][2]['name']); - $I->assertEquals('MultipleParams', $parsing['methods']['testMethod1'][3]['name']); - $I->assertEquals('NamedMultipleParams', $parsing['methods']['testMethod1'][4]['name']); + $expected = 4; + $actual = $parsing['methods']; + $I->assertCount($expected, $actual); + + $actual = isset($parsing['methods']); + $I->assertTrue($actual); + + // Multiple well-ordered annotations + $expected = 5; + $actual = $parsing['methods']['testMethod1']; + $I->assertCount($expected, $actual); + + $actual = isset($parsing['methods']['testMethod1']); + $I->assertTrue($actual); + + $expected = 'return'; + $actual = $parsing['methods']['testMethod1'][0]['name']; + $I->assertSame($expected, $actual); + + $expected = 'Simple'; + $actual = $parsing['methods']['testMethod1'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'SingleParam'; + $actual = $parsing['methods']['testMethod1'][2]['name']; + $I->assertSame($expected, $actual); + + $expected = 'MultipleParams'; + $actual = $parsing['methods']['testMethod1'][3]['name']; + $I->assertSame($expected, $actual); + + $expected = 'NamedMultipleParams'; + $actual = $parsing['methods']['testMethod1'][4]['name']; + $I->assertSame($expected, $actual); // Comment without content - $I->assertFalse( - isset($parsing['methods']['testMethod2']) - ); + $actual = isset($parsing['methods']['testMethod2']); + $I->assertFalse($actual); // Same line annotations - $I->assertCount(3, $parsing['methods']['testMethod3']); - $I->assertEquals('Simple', $parsing['methods']['testMethod3'][0]['name']); - $I->assertEquals('SingleParam', $parsing['methods']['testMethod3'][1]['name']); - $I->assertEquals('MultipleParams', $parsing['methods']['testMethod3'][2]['name']); + $expected = 3; + $actual = $parsing['methods']['testMethod3']; + $I->assertCount($expected, $actual); + + $expected = 'Simple'; + $actual = $parsing['methods']['testMethod3'][0]['name']; + $I->assertSame($expected, $actual); + + $expected = 'SingleParam'; + $actual = $parsing['methods']['testMethod3'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'MultipleParams'; + $actual = $parsing['methods']['testMethod3'][2]['name']; + $I->assertSame($expected, $actual); // Unordered annotations - $I->assertCount(3, $parsing['methods']['testMethod4']); - $I->assertEquals('Simple', $parsing['methods']['testMethod4'][0]['name']); - $I->assertEquals('SingleParam', $parsing['methods']['testMethod4'][1]['name']); - $I->assertEquals('MultipleParams', $parsing['methods']['testMethod4'][2]['name']); + $expected = 3; + $actual = $parsing['methods']['testMethod4']; + $I->assertCount($expected, $actual); + + $expected = 'Simple'; + $actual = $parsing['methods']['testMethod4'][0]['name']; + $I->assertSame($expected, $actual); + + $expected = 'SingleParam'; + $actual = $parsing['methods']['testMethod4'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'MultipleParams'; + $actual = $parsing['methods']['testMethod4'][2]['name']; + $I->assertSame($expected, $actual); + // Unordered annotations + extra content - $I->assertCount(3, $parsing['methods']['testMethod5']); - $I->assertEquals('Simple', $parsing['methods']['testMethod5'][0]['name']); - $I->assertEquals('SingleParam', $parsing['methods']['testMethod5'][1]['name']); - $I->assertEquals('MultipleParams', $parsing['methods']['testMethod5'][2]['name']); + $expected = 3; + $actual = $parsing['methods']['testMethod5']; + $I->assertCount($expected, $actual); + + $expected = 'Simple'; + $actual = $parsing['methods']['testMethod5'][0]['name']; + $I->assertSame($expected, $actual); + + $expected = 'SingleParam'; + $actual = $parsing['methods']['testMethod5'][1]['name']; + $I->assertSame($expected, $actual); + + $expected = 'MultipleParams'; + $actual = $parsing['methods']['testMethod5'][2]['name']; + $I->assertSame($expected, $actual); } } diff --git a/tests/unit/Annotations/Reader/ParseDocBlockCest.php b/tests/unit/Annotations/Reader/ParseDocBlockCest.php index 6492557a153..953b7b6f6cf 100644 --- a/tests/unit/Annotations/Reader/ParseDocBlockCest.php +++ b/tests/unit/Annotations/Reader/ParseDocBlockCest.php @@ -16,6 +16,8 @@ use Phalcon\Annotations\Reader; use UnitTester; +use function ksort; + class ParseDocBlockCest { /** @@ -43,98 +45,104 @@ public function annotationsReaderParseDocBlock(UnitTester $I) $parsed = $reader->parseDocBlock($docBlock); $I->assertIsArray($parsed); - $I->assertCount(4, $parsed); - $I->assertEquals( - [ - 'type' => 300, - 'name' => 'var', - 'file' => 'eval code', - 'line' => 1, - ], - $parsed[0] - ); - $I->assertEquals( - [ - 'type' => 300, - 'name' => 'Simple', - 'file' => 'eval code', - 'line' => 1, - ], - $parsed[1] - ); - $I->assertEquals( - [ - 'type' => 300, - 'name' => 'SingleParam', - 'file' => 'eval code', - 'line' => 1, - 'arguments' => [ - [ - 'expr' => [ - 'type' => 303, - 'value' => 'Param', - ], + $expected = 4; + $actual = $parsed; + $I->assertCount($expected, $actual); + + $expected = [ + 'file' => 'eval code', + 'line' => 1, + 'name' => 'var', + 'type' => 300, + ]; + ksort($parsed[0]); + $actual = $parsed[0]; + $I->assertSame($expected, $actual); + + $expected = [ + 'file' => 'eval code', + 'line' => 1, + 'name' => 'Simple', + 'type' => 300, + ]; + ksort($parsed[1]); + $actual = $parsed[1]; + $I->assertSame($expected, $actual); + + $expected = [ + 'arguments' => [ + [ + 'expr' => [ + 'type' => 303, + 'value' => 'Param', ], ], ], - $parsed[2] - ); - $I->assertEquals( - [ - 'type' => 300, - 'name' => 'MultipleParams', - 'file' => 'eval code', - 'line' => 1, - 'arguments' => [ - [ - 'expr' => [ - 'type' => 303, - 'value' => 'First', - ], + 'file' => 'eval code', + 'line' => 1, + 'name' => 'SingleParam', + 'type' => 300, + ]; + ksort($parsed[2]); + $actual = $parsed[2]; + $I->assertSame($expected, $actual); + + $expected = [ + 'arguments' => [ + [ + 'expr' => [ + 'type' => 303, + 'value' => 'First', ], - [ - 'expr' => [ - 'type' => 307, - 'value' => 'Second', - ], + ], + [ + 'expr' => [ + 'type' => 307, + 'value' => 'Second', ], - [ - 'expr' => [ - 'type' => 301, - 'value' => '1', - ], + ], + [ + 'expr' => [ + 'type' => 301, + 'value' => '1', ], - [ - 'expr' => [ - 'type' => 302, - 'value' => '1.1', - ], + ], + [ + 'expr' => [ + 'type' => 302, + 'value' => '1.1', ], - [ - 'expr' => [ - 'type' => 301, - 'value' => '-10', - ], + ], + [ + 'expr' => [ + 'type' => 301, + 'value' => '-10', ], - [ - 'expr' => [ - 'type' => 305, - ], + ], + [ + 'expr' => [ + 'type' => 305, ], - [ - 'expr' => [ - 'type' => 306, - ], + ], + [ + 'expr' => [ + 'type' => 306, ], - [ - 'expr' => [ - 'type' => 304, - ], + ], + [ + 'expr' => [ + 'type' => 304, ], ], ], - $parsed[3] - ); + 'file' => 'eval code', + 'line' => 1, + 'name' => 'MultipleParams', + 'type' => 300, + ]; + ksort($parsed[3]); + $actual = $parsed[3]; + $I->assertSame($expected, $actual); } } diff --git a/tests/unit/Annotations/Reflection/ConstructCest.php b/tests/unit/Annotations/Reflection/ConstructCest.php index 8563ea60f13..139e39da6a5 100644 --- a/tests/unit/Annotations/Reflection/ConstructCest.php +++ b/tests/unit/Annotations/Reflection/ConstructCest.php @@ -13,11 +13,26 @@ namespace Phalcon\Tests\Unit\Annotations\Reflection; +use Phalcon\Annotations\Annotation; +use Phalcon\Annotations\Collection; +use Phalcon\Annotations\Reader; use Phalcon\Annotations\Reflection; use UnitTester; +use function dataDir; + class ConstructCest { + /** + * Executed before each test. + * + * @param UnitTester $I + */ + protected function _before(UnitTester $I) + { + require_once dataDir('fixtures/Annotations/TestClass.php'); + } + /** * Tests Phalcon\Annotations\Reflection :: __construct() * @@ -32,4 +47,144 @@ public function annotationsReflectionConstruct(UnitTester $I) $I->assertInstanceOf(Reflection::class, $reflection); } + + /** + * Tests parsing class annotations + * + * @param UnitTester $I + * + * @author Phalcon Team + * @since 2016-01-26 + */ + public function testClassAnnotations(UnitTester $I) + { + $reader = new Reader(); + + $reflection = new Reflection( + $reader->parse('TestClass') + ); + + $constantsAnnotations = $reflection->getConstantsAnnotations(); + $I->assertIsArray($constantsAnnotations); + + $annotations = $constantsAnnotations['TEST_CONST1']; + + $expected = Collection::class; + $actual = $annotations; + $I->assertInstanceOf($expected, $actual); + + $actual = $annotations->has('Simple'); + $I->assertTrue($actual); + + $methodsAnnotations = $reflection->getMethodsAnnotations(); + + $I->assertIsArray($methodsAnnotations); + + $expected = Collection::class; + $actual = $methodsAnnotations['testMethod1']; + $I->assertInstanceOf($expected, $actual); + + $total = 0; + + foreach ($methodsAnnotations as $method => $annotations) { + $I->assertIsString($method); + + $number = 0; + + foreach ($annotations as $annotation) { + $expected = Annotation::class; + $actual = $annotation; + $I->assertInstanceOf($expected, $actual); + + $number++; + $total++; + } + + $I->assertGreaterThan(0, $number); + } + + $expected = 14; + $actual = $total; + $I->assertSame($expected, $actual); + + /** @var Collection $annotations */ + $annotations = $methodsAnnotations['testMethod1']; + + $actual = $annotations->has('Simple'); + $I->assertTrue($actual); + + $actual = $annotations->has('NoSimple'); + $I->assertFalse($actual); + + $annotation = $annotations->get('Simple'); + + $expected = 'Simple'; + $actual = $annotation->getName(); + $I->assertSame($expected, $actual); + + $expected = []; + $actual = $annotation->getArguments(); + $I->assertSame($expected, $actual); + + $expected = 0; + $actual = $annotation->numberArguments(); + $I->assertSame($expected, $actual); + + + $actual = $annotation->hasArgument('none'); + $I->assertFalse($actual); + + $annotation = $annotations->get('NamedMultipleParams'); + $expected = 'NamedMultipleParams'; + $actual = $annotation->getName(); + $I->assertSame($expected, $actual); + + $expected = 2; + $actual = $annotation->numberArguments(); + $I->assertSame($expected, $actual); + + $expected = ['first' => 'First', 'second' => 'Second']; + $actual = $annotation->getArguments(); + $I->assertSame($expected, $actual); + + $actual = $annotation->hasArgument('first'); + $I->assertTrue($actual); + + $I->assertSame('First', $annotation->getArgument('first')); + + $actual = $annotation->hasArgument('none'); + $I->assertFalse($actual); + + $propertiesAnnotations = $reflection->getPropertiesAnnotations(); + $I->assertIsArray($propertiesAnnotations); + + $expected = Collection::class; + $actual = $propertiesAnnotations['testProp1']; + $I->assertInstanceOf($expected, $actual); + + $total = 0; + + foreach ($propertiesAnnotations as $annotations) { + $expected = Collection::class; + $actual = $propertiesAnnotations['testProp1']; + $I->assertInstanceOf($expected, $actual); + + $number = 0; + + foreach ($annotations as $annotation) { + $expected = Annotation::class; + $actual = $annotation; + $I->assertInstanceOf($expected, $actual); + + $number++; + $total++; + } + + $I->assertGreaterThan(0, $number); + } + + $expected = 10; + $actual = $total; + $I->assertSame($expected, $actual); + } } diff --git a/tests/unit/Annotations/Reflection/GetClassAnnotationsCest.php b/tests/unit/Annotations/Reflection/GetClassAnnotationsCest.php index 09f07446621..69f6b0b153a 100644 --- a/tests/unit/Annotations/Reflection/GetClassAnnotationsCest.php +++ b/tests/unit/Annotations/Reflection/GetClassAnnotationsCest.php @@ -39,9 +39,8 @@ public function testEmptyReflection(UnitTester $I) { $reflection = new Reflection(); - $I->assertNull( - $reflection->getClassAnnotations() - ); + $actual = $reflection->getClassAnnotations(); + $I->assertNull($actual); } /** @@ -60,23 +59,26 @@ public function testParsingARealClass(UnitTester $I) $classAnnotations = $reflection->getClassAnnotations(); - $I->assertInstanceOf( - Collection::class, - $classAnnotations - ); + $expected = Collection::class; + $actual = $classAnnotations; + $I->assertInstanceOf($expected, $actual); $number = 0; foreach ($classAnnotations as $annotation) { - $I->assertInstanceOf( - Annotation::class, - $annotation - ); + $expected = Annotation::class; + $actual = $annotation; + $I->assertInstanceOf($expected, $actual); $number++; } - $I->assertEquals(9, $number); - $I->assertCount(9, $classAnnotations); + $expected = 9; + $actual = $number; + $I->assertSame($expected, $actual); + + $expected = 9; + $actual = $classAnnotations; + $I->assertCount($expected, $actual); } } diff --git a/tests/unit/Annotations/Reflection/GetMethodsAnnotationsCest.php b/tests/unit/Annotations/Reflection/GetMethodsAnnotationsCest.php index 277ca1fd136..8dd32f3aa1c 100644 --- a/tests/unit/Annotations/Reflection/GetMethodsAnnotationsCest.php +++ b/tests/unit/Annotations/Reflection/GetMethodsAnnotationsCest.php @@ -40,12 +40,9 @@ public function testEmptyReflection(UnitTester $I) { $reflection = new Reflection(); - $I->assertIsArray( - $reflection->getMethodsAnnotations() - ); - $I->assertIsEmpty( - $reflection->getMethodsAnnotations() - ); + $actual = $reflection->getMethodsAnnotations(); + $I->assertIsArray($actual); + $I->assertIsEmpty($actual); } /** @@ -65,21 +62,24 @@ public function annotationsReflectionGetMethodsAnnotations(UnitTester $I) ); $methodsAnnotations = $reflection->getMethodsAnnotations(); - $I->assertIsArray($methodsAnnotations); $number = 0; foreach ($methodsAnnotations as $annotation) { - $I->assertInstanceOf( - Collection::class, - $annotation - ); + $expected = Collection::class; + $actual = $annotation; + $I->assertInstanceOf($expected, $actual); $number++; } - $I->assertEquals(4, $number); - $I->assertCount(4, $methodsAnnotations); + $expected = 4; + $actual = $number; + $I->assertSame($expected, $actual); + + $expected = 4; + $actual = $methodsAnnotations; + $I->assertCount($expected, $actual); } } diff --git a/tests/unit/Annotations/Reflection/GetPropertiesAnnotationsCest.php b/tests/unit/Annotations/Reflection/GetPropertiesAnnotationsCest.php index d672d877036..b4bc4363c10 100644 --- a/tests/unit/Annotations/Reflection/GetPropertiesAnnotationsCest.php +++ b/tests/unit/Annotations/Reflection/GetPropertiesAnnotationsCest.php @@ -40,12 +40,9 @@ public function testEmptyReflection(UnitTester $I) { $reflection = new Reflection(); - $I->assertIsArray( - $reflection->getPropertiesAnnotations() - ); - $I->assertIsEmpty( - $reflection->getPropertiesAnnotations() - ); + $actual = $reflection->getPropertiesAnnotations(); + $I->assertIsArray($actual); + $I->assertIsEmpty($actual); } /** @@ -71,15 +68,19 @@ public function annotationsReflectionGetPropertiesAnnotations(UnitTester $I) $number = 0; foreach ($propertiesAnnotations as $annotation) { - $I->assertInstanceOf( - Collection::class, - $annotation - ); + $expected = Collection::class; + $actual = $annotation; + $I->assertInstanceOf($expected, $actual); $number++; } - $I->assertEquals(3, $number); - $I->assertCount(3, $propertiesAnnotations); + $expected = 3; + $actual = $number; + $I->assertSame($expected, $actual); + + $expected = 3; + $actual = $propertiesAnnotations; + $I->assertCount($expected, $actual); } } diff --git a/tests/unit/Annotations/Reflection/GetReflectionDataCest.php b/tests/unit/Annotations/Reflection/GetReflectionDataCest.php index 989e9b056d2..049530c34ea 100644 --- a/tests/unit/Annotations/Reflection/GetReflectionDataCest.php +++ b/tests/unit/Annotations/Reflection/GetReflectionDataCest.php @@ -30,7 +30,8 @@ public function annotationsReflectionGetReflectionData(UnitTester $I) $reflection = new Reflection(); - $I->assertIsArray($reflection->getReflectionData()); - $I->assertIsEmpty($reflection->getReflectionData()); + $actual = $reflection->getReflectionData(); + $I->assertIsArray($actual); + $I->assertIsEmpty($actual); } } diff --git a/tests/unit/Annotations/ReflectionCest.php b/tests/unit/Annotations/ReflectionCest.php deleted file mode 100644 index 17aeac7e65e..00000000000 --- a/tests/unit/Annotations/ReflectionCest.php +++ /dev/null @@ -1,141 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE.txt - * file that was distributed with this source code. - */ - -namespace Phalcon\Tests\Unit\Annotations; - -use Phalcon\Annotations\Annotation; -use Phalcon\Annotations\Collection; -use Phalcon\Annotations\Reader; -use Phalcon\Annotations\Reflection; -use UnitTester; - -class ReflectionCest -{ - /** - * Executed before each test. - * - * @param UnitTester $I - */ - protected function _before(UnitTester $I) - { - require_once dataDir('fixtures/Annotations/TestClass.php'); - } - - /** - * Tests parsing class annotations - * - * @param UnitTester $I - * - * @author Phalcon Team - * @since 2016-01-26 - */ - public function testClassAnnotations(UnitTester $I) - { - $reader = new Reader(); - - $reflection = new Reflection( - $reader->parse('TestClass') - ); - - $constantsAnnotations = $reflection->getConstantsAnnotations(); - $I->assertIsArray($constantsAnnotations); - - $annotations = $constantsAnnotations['TEST_CONST1']; - $I->assertInstanceOf( - Collection::class, - $annotations - ); - $I->assertTrue($annotations->has('Simple')); - - $methodsAnnotations = $reflection->getMethodsAnnotations(); - - $I->assertIsArray($methodsAnnotations); - - $I->assertInstanceOf( - Collection::class, - $methodsAnnotations['testMethod1'] - ); - - $total = 0; - - foreach ($methodsAnnotations as $method => $annotations) { - $I->assertIsString($method); - - $number = 0; - - foreach ($annotations as $annotation) { - $I->assertInstanceOf( - Annotation::class, - $annotation - ); - - $number++; - $total++; - } - - $I->assertGreaterThan(0, $number); - } - - $I->assertEquals(14, $total); - - /** @var Collection $annotations */ - $annotations = $methodsAnnotations['testMethod1']; - - $I->assertTrue($annotations->has('Simple')); - $I->assertFalse($annotations->has('NoSimple')); - - $annotation = $annotations->get('Simple'); - $I->assertEquals('Simple', $annotation->getName()); - $I->assertEquals([], $annotation->getArguments()); - $I->assertEquals(0, $annotation->numberArguments()); - $I->assertFalse($annotation->hasArgument('none')); - - $annotation = $annotations->get('NamedMultipleParams'); - $I->assertEquals('NamedMultipleParams', $annotation->getName()); - $I->assertEquals(2, $annotation->numberArguments()); - $I->assertEquals(['first' => 'First', 'second' => 'Second'], $annotation->getArguments()); - $I->assertTrue($annotation->hasArgument('first')); - $I->assertEquals('First', $annotation->getArgument('first')); - $I->assertFalse($annotation->hasArgument('none')); - - $propertiesAnnotations = $reflection->getPropertiesAnnotations(); - $I->assertIsArray($propertiesAnnotations); - $I->assertInstanceOf( - Collection::class, - $propertiesAnnotations['testProp1'] - ); - - $total = 0; - - foreach ($propertiesAnnotations as $property => $annotations) { - $I->assertInstanceOf( - Collection::class, - $propertiesAnnotations['testProp1'] - ); - - $number = 0; - - foreach ($annotations as $annotation) { - $I->assertInstanceOf( - Annotation::class, - $annotation - ); - - $number++; - $total++; - } - - $I->assertGreaterThan(0, $number); - } - - $I->assertEquals(10, $total); - } -} diff --git a/tests/unit/Di/GetDICest.php b/tests/unit/Di/GetDICest.php index 8e93fe4eb34..c8913592e11 100644 --- a/tests/unit/Di/GetDICest.php +++ b/tests/unit/Di/GetDICest.php @@ -25,9 +25,9 @@ final class GetDICest /** * Unit Tests Phalcon\Di\Injectable :: getDI() * - * Test when an Injectable object has no DI set and a call has been made to getDI(), - * should set the container property. - * It's tested with the Controller class + * Test when an Injectable object has no DI set and a call has been made to + * getDI(), should set the container property. It's tested with the + * Controller class * * @throws ReflectionException * @since 2020-08-13 diff --git a/tests/unit/Di/GetSetInternalEventsManagerCest.php b/tests/unit/Di/GetSetInternalEventsManagerCest.php index 9cc4be9ee97..d67d56bd65e 100644 --- a/tests/unit/Di/GetSetInternalEventsManagerCest.php +++ b/tests/unit/Di/GetSetInternalEventsManagerCest.php @@ -26,7 +26,8 @@ class GetSetInternalEventsManagerCest { /** - * Unit Tests Phalcon\Di\Di :: getInternalEventsManager()/setInternalEventsManager() + * Unit Tests Phalcon\Di\Di :: + * getInternalEventsManager()/setInternalEventsManager() * * @param UnitTester $I * diff --git a/tests/unit/Di/Injectable/UnderscoreGetCest.php b/tests/unit/Di/Injectable/UnderscoreGetCest.php index 99fd3d9adc9..856a8945b81 100644 --- a/tests/unit/Di/Injectable/UnderscoreGetCest.php +++ b/tests/unit/Di/Injectable/UnderscoreGetCest.php @@ -92,14 +92,13 @@ public function diInjectableUnderscoreGetException(UnitTester $I) $component = $container->get('component'); - $I->expectThrowable( - new Exception( - 'Access to undefined property unknown', - 1024 - ), - function () use ($component) { - $result = $component->unknown; - } - ); + $expected = 'Access to undefined property unknown'; + $actual = ''; + try { + $result = $component->unknown; + } catch (Exception $ex) { + $actual = $ex->getMessage(); + } + $I->assertStringContainsString($expected, $actual); } } diff --git a/tests/unit/Encryption/Crypt/EncryptCest.php b/tests/unit/Encryption/Crypt/EncryptCest.php index 1ce0d41accf..f3f456018f8 100644 --- a/tests/unit/Encryption/Crypt/EncryptCest.php +++ b/tests/unit/Encryption/Crypt/EncryptCest.php @@ -18,6 +18,7 @@ use Phalcon\Encryption\Crypt\Exception\Exception; use Phalcon\Tests\Fixtures\Crypt\CryptFixture; use UnitTester; +use ValueError; use function str_repeat; use function substr; @@ -305,7 +306,9 @@ function () { Crypt::class, [], [ - 'phpOpensslRandomPseudoBytes' => false, + 'phpOpensslRandomPseudoBytes' => function () { + throw new ValueError(); + }, ] ); diff --git a/tests/unit/Html/Attributes/ToStringCest.php b/tests/unit/Html/Attributes/ToStringCest.php index 3e13f2e59a0..da6327fab2b 100644 --- a/tests/unit/Html/Attributes/ToStringCest.php +++ b/tests/unit/Html/Attributes/ToStringCest.php @@ -14,6 +14,7 @@ namespace Phalcon\Tests\Unit\Html\Attributes; use Phalcon\Html\Attributes; +use Phalcon\Html\Exception; use Phalcon\Tests\Fixtures\Traits\DiTrait; use UnitTester; @@ -50,4 +51,31 @@ public function htmlAttributesToString(UnitTester $I) (string)$attributes ); } + + /** + * Tests Phalcon\Html\Attributes :: __toString() - exception + * + * @author Phalcon Team + * @since 2023-09-26 + */ + public function htmlAttributesToStringException(UnitTester $I) + { + $I->wantToTest('Html\Attributes - __toString() - exception'); + + $I->expectThrowable( + new Exception( + 'Value at index: "value" type: "array" cannot be rendered' + ), + function () { + $attributes = new Attributes( + [ + 'name' => 'q', + 'value' => ['one' => 'two'], + ] + ); + + (string)$attributes; + } + ); + } } diff --git a/tests/unit/Html/Helper/Meta/ToStringCest.php b/tests/unit/Html/Helper/Meta/ToStringCest.php index 0fb01f6f575..5de28c025e8 100644 --- a/tests/unit/Html/Helper/Meta/ToStringCest.php +++ b/tests/unit/Html/Helper/Meta/ToStringCest.php @@ -15,6 +15,8 @@ use Phalcon\Html\Helper\Meta; use UnitTester; +use const PHP_EOL; + /** * Class ToStringCest * @@ -42,4 +44,42 @@ public function htmlHelperMetaToStringEmpty(UnitTester $I) $actual = (string)$result; $I->assertEmpty($actual); } + + /** + * Tests Phalcon\Html\Helper\Meta :: __toString() - retains value + * + * @param UnitTester $I + * + * @author Phalcon Team + * @since 2023-09-26 + * @issue https://github.com/phalcon/cphalcon/issues/16441 + */ + public function htmlHelperMetaToStringRetainsValue(UnitTester $I) + { + $I->wantToTest('Html\Helper\Meta - __toString() - retains value'); + + $escaper = new Escaper(); + $meta = new Meta($escaper); + $meta + ->addName('robots', 'index, nofollow') + ->addName('author', 'Me') + ; + + $expected = ' ' + . PHP_EOL + . ' ' + . PHP_EOL; + $actual = (string)$meta; + $I->assertSame($expected, $actual); + + $meta = new Meta($escaper); + $meta->addName('robots', 'index, nofollow'); + + $expected = ' ' + . PHP_EOL + . ' ' + . PHP_EOL; + $actual = (string)$meta->addName('author', 'Me'); + $I->assertSame($expected, $actual); + } } diff --git a/tests/unit/Http/Cookie/ConstructCest.php b/tests/unit/Http/Cookie/ConstructCest.php index 6d81387bc86..1e3bf4a5ad2 100644 --- a/tests/unit/Http/Cookie/ConstructCest.php +++ b/tests/unit/Http/Cookie/ConstructCest.php @@ -14,13 +14,14 @@ namespace Phalcon\Tests\Unit\Http\Cookie; use Phalcon\Http\Cookie; -use Phalcon\Tests\Fixtures\Traits\DiTrait; +use Phalcon\Http\Cookie\CookieInterface; +use Phalcon\Tests\Unit\Http\Helper\HttpBase; use UnitTester; -class ConstructCest -{ - use DiTrait; +use function uniqid; +class ConstructCest extends HttpBase +{ /** * Tests Phalcon\Http\Cookie :: __construct() * @@ -31,11 +32,12 @@ public function httpCookieConstruct(UnitTester $I) { $I->wantToTest('Http\Cookie - __construct()'); - $this->setNewFactoryDefault(); $this->setDiService('sessionStream'); - $cookie = new Cookie('test'); - $I->assertInstanceOf(Cookie\CookieInterface::class, $cookie); + $name = uniqid('nam-'); + $cookie = new Cookie($name); + + $I->assertInstanceOf(CookieInterface::class, $cookie); $I->assertInstanceOf(Cookie::class, $cookie); } } diff --git a/tests/unit/Logger/Adapter/Noop/SerializeUnserializeCest.php b/tests/unit/Logger/Adapter/Noop/SerializeUnserializeCest.php index 9f4e3652a98..77a0d28636b 100644 --- a/tests/unit/Logger/Adapter/Noop/SerializeUnserializeCest.php +++ b/tests/unit/Logger/Adapter/Noop/SerializeUnserializeCest.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Phalcon\Test\Unit\Logger\Adapter\Noop; +namespace Phalcon\Tests\Unit\Logger\Adapter\Noop; use Phalcon\Logger\Adapter\Noop; use Phalcon\Logger\Exception; diff --git a/tests/unit/Logger/Adapter/Stream/SerializeUnserializeCest.php b/tests/unit/Logger/Adapter/Stream/SerializeUnserializeCest.php index 7d729f61175..2203f8856d9 100644 --- a/tests/unit/Logger/Adapter/Stream/SerializeUnserializeCest.php +++ b/tests/unit/Logger/Adapter/Stream/SerializeUnserializeCest.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Phalcon\Test\Unit\Logger\Adapter\Stream; +namespace Phalcon\Tests\Unit\Logger\Adapter\Stream; use Phalcon\Logger\Adapter\Stream; use Phalcon\Logger\Exception; diff --git a/tests/unit/Logger/Adapter/Syslog/SerializeUnserializeCest.php b/tests/unit/Logger/Adapter/Syslog/SerializeUnserializeCest.php index 0158676b22a..9469344c889 100644 --- a/tests/unit/Logger/Adapter/Syslog/SerializeUnserializeCest.php +++ b/tests/unit/Logger/Adapter/Syslog/SerializeUnserializeCest.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Phalcon\Test\Unit\Logger\Adapter\Syslog; +namespace Phalcon\Tests\Unit\Logger\Adapter\Syslog; use Phalcon\Logger\Adapter\Syslog; use Phalcon\Logger\Exception; diff --git a/tests/unit/Logger/Formatter/Json/FormatCest.php b/tests/unit/Logger/Formatter/Json/FormatCest.php index 8fd1777ba1c..eeae0882e95 100644 --- a/tests/unit/Logger/Formatter/Json/FormatCest.php +++ b/tests/unit/Logger/Formatter/Json/FormatCest.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Phalcon\Testss\Unit\Logger\Formatter\Json; +namespace Phalcon\Tests\Unit\Logger\Formatter\Json; use DateTimeImmutable; use DateTimeZone; diff --git a/tests/unit/Logger/Logger/LogCest.php b/tests/unit/Logger/Logger/LogCest.php index f637f5cabac..19d031acac2 100644 --- a/tests/unit/Logger/Logger/LogCest.php +++ b/tests/unit/Logger/Logger/LogCest.php @@ -221,54 +221,4 @@ public function loggerLogLogInterpolator(UnitTester $I) $adapter->close(); $I->safeDeleteFile($fileName); } - - /** - * Tests Phalcon\Logger :: log() - interpolator custom - * - * @param UnitTester $I - * - * @author Phalcon Team - * @since 2022-09-11 - */ - public function loggerLogLogInterpolatorCustom(UnitTester $I) - { - $I->wantToTest('Logger - log() - interpolator custom'); - - $logPath = logsDir(); - $fileName = $I->getNewFileName('log', 'log'); - $formatter = new Line( - '{message}-[{level}]-{server}:{user}', - 'U.u', - '{', - '}' - ); - $context = [ - 'server' => uniqid('srv-'), - 'user' => uniqid('usr-'), - ]; - $adapter = new Stream($logPath . $fileName); - $adapter->setFormatter($formatter); - - $logger = new Logger( - 'my-logger', - [ - 'one' => $adapter, - ] - ); - - $logger->log(Enum::DEBUG, 'log message', $context); - - $I->amInPath($logPath); - $I->openFile($fileName); - - $expected = sprintf( - 'log message-[DEBUG]-%s:%s', - $context['server'], - $context['user'] - ); - $I->seeInThisFile($expected); - - $adapter->close(); - $I->safeDeleteFile($fileName); - } } diff --git a/tests/unit/Tag/AppendTitleCest.php b/tests/unit/Tag/AppendTitleCest.php new file mode 100644 index 00000000000..0be52085044 --- /dev/null +++ b/tests/unit/Tag/AppendTitleCest.php @@ -0,0 +1,187 @@ + + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class AppendTitleCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: appendTitle() + * + * @author Phalcon Team + * @since 2012-09-05 + */ + public function tagAppendTitle(UnitTester $I) + { + $I->wantToTest('Tag - appendTitle()'); + + Tag::resetInput(); + + Tag::setTitle('Title'); + + Tag::appendTitle('Class'); + + $I->assertSame( + 'Title', + Tag::getTitle(false, false) + ); + + $I->assertSame( + 'TitleClass', + Tag::getTitle(false, true) + ); + + $I->assertSame( + 'TitleClass' . PHP_EOL, + Tag::renderTitle() + ); + } + + /** + * Tests Phalcon\Tag :: appendTitle() - separator + * + * @author Phalcon Team + * @since 2012-09-05 + */ + public function tagAppendTitleSeparator(UnitTester $I) + { + $I->wantToTest('Tag - appendTitle() - separator'); + + Tag::resetInput(); + + Tag::setTitle('Title'); + Tag::setTitleSeparator('|'); + + Tag::appendTitle('Class'); + + $I->assertSame( + 'Title', + Tag::getTitle(false, false) + ); + + $I->assertSame( + 'Title|Class', + Tag::getTitle(false, true) + ); + + $I->assertSame( + 'Title|Class' . PHP_EOL, + Tag::renderTitle() + ); + } + + /** + * Tests Phalcon\Tag :: appendTitle() - double call + * + * @author Phalcon Team + * @since 2012-09-05 + */ + public function tagAppendTitleDoubleCall(UnitTester $I) + { + $I->wantToTest('Tag - appendTitle() - double call'); + + Tag::resetInput(); + + Tag::setTitle('Main'); + Tag::setTitleSeparator(' - '); + + Tag::appendTitle('Category'); + Tag::appendTitle('Title'); + + $I->assertSame( + 'Main', + Tag::getTitle(false, false) + ); + + $I->assertSame( + 'Main - Category - Title', + Tag::getTitle(false, true) + ); + + $I->assertSame( + 'Main - Category - Title' . PHP_EOL, + Tag::renderTitle() + ); + } + + /** + * Tests Phalcon\Tag :: appendTitle() - array + * + * @author Phalcon Team + * @since 2012-09-05 + */ + public function tagAppendTitleArray(UnitTester $I) + { + $I->wantToTest('Tag - appendTitle() - array'); + + Tag::resetInput(); + + Tag::setTitle('Main'); + Tag::setTitleSeparator(' - '); + + Tag::appendTitle(['Category', 'Title']); + + $I->assertSame( + 'Main', + Tag::getTitle(false, false) + ); + + $I->assertSame( + 'Main - Category - Title', + Tag::getTitle(false, true) + ); + + $I->assertSame( + 'Main - Category - Title' . PHP_EOL, + Tag::renderTitle() + ); + } + + /** + * Tests Phalcon\Tag :: appendTitle() - empty array + * + * @author Phalcon Team + * @since 2012-09-05 + */ + public function tagAppendTitleEmptyArray(UnitTester $I) + { + $I->wantToTest('Tag - appendTitle() - empty array'); + + Tag::resetInput(); + + Tag::setTitle('Main'); + Tag::setTitleSeparator(' - '); + + Tag::appendTitle('Category'); + Tag::appendTitle([]); + + $I->assertSame( + 'Main', + Tag::getTitle(false, false) + ); + + $I->assertSame( + 'Main', + Tag::getTitle(false, true) + ); + + $I->assertSame( + 'Main' . PHP_EOL, + Tag::renderTitle() + ); + } +} diff --git a/tests/unit/Tag/CheckFieldCest.php b/tests/unit/Tag/CheckFieldCest.php new file mode 100644 index 00000000000..6bdd6c22193 --- /dev/null +++ b/tests/unit/Tag/CheckFieldCest.php @@ -0,0 +1,139 @@ + + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagHelper; +use UnitTester; + +class CheckFieldCest extends TagHelper +{ + protected $function = 'checkField'; + protected $inputType = 'checkbox'; + + /** + * Tests Phalcon\Tag :: weekField() - setDefault + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagFieldWithSetDefault(UnitTester $I) + { + $I->wantToTest( + sprintf( + 'Tag - %s() - setDefault()', + $this->function + ) + ); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = 'testFieldParameter($I, $this->function, $options, $expected, false, 'setDefault'); + $this->testFieldParameter($I, $this->function, $options, $expected, true, 'setDefault'); + } + + /** + * Tests Phalcon\Tag :: weekField() - displayTo + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagFieldWithDisplayTo(UnitTester $I) + { + $I->wantToTest( + sprintf( + 'Tag - %s() - string displayTo()', + $this->function + ) + ); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = 'testFieldParameter($I, $this->function, $options, $expected, false, 'displayTo'); + $this->testFieldParameter($I, $this->function, $options, $expected, true, 'displayTo'); + } + + /** + * Tests Phalcon\Tag :: weekField() - setDefault and element not present + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagFieldWithSetDefaultElementNotPresent(UnitTester $I) + { + $I->wantToTest( + sprintf( + 'Tag - %s() - setDefault() element not present', + $this->function + ) + ); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = 'testFieldParameter($I, $this->function, $options, $expected, false, 'setDefault'); + $this->testFieldParameter($I, $this->function, $options, $expected, true, 'setDefault'); + } + + /** + * Tests Phalcon\Tag :: weekField() - displayTo and element not present + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagFieldWithDisplayToElementNotPresent(UnitTester $I) + { + $I->wantToTest( + sprintf( + 'Tag - %s() - displayTo() element not present', + $this->function + ) + ); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = 'testFieldParameter($I, $this->function, $options, $expected, false, 'displayTo'); + $this->testFieldParameter($I, $this->function, $options, $expected, true, 'displayTo'); + } +} diff --git a/tests/unit/Tag/ColorFieldCest.php b/tests/unit/Tag/ColorFieldCest.php new file mode 100644 index 00000000000..51cb210fb0b --- /dev/null +++ b/tests/unit/Tag/ColorFieldCest.php @@ -0,0 +1,22 @@ + + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagHelper; + +class ColorFieldCest extends TagHelper +{ + protected $function = 'colorField'; + protected $inputType = 'color'; +} diff --git a/tests/unit/Tag/DateFieldCest.php b/tests/unit/Tag/DateFieldCest.php new file mode 100644 index 00000000000..727343ec633 --- /dev/null +++ b/tests/unit/Tag/DateFieldCest.php @@ -0,0 +1,22 @@ + + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagHelper; + +class DateFieldCest extends TagHelper +{ + protected $function = 'dateField'; + protected $inputType = 'date'; +} diff --git a/tests/unit/Tag/DateTimeFieldCest.php b/tests/unit/Tag/DateTimeFieldCest.php new file mode 100644 index 00000000000..45585f8a00b --- /dev/null +++ b/tests/unit/Tag/DateTimeFieldCest.php @@ -0,0 +1,22 @@ + + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagHelper; + +class DateTimeFieldCest extends TagHelper +{ + protected $function = 'dateTimeField'; + protected $inputType = 'datetime'; +} diff --git a/tests/unit/Tag/DateTimeLocalFieldCest.php b/tests/unit/Tag/DateTimeLocalFieldCest.php new file mode 100644 index 00000000000..d9a658d9a01 --- /dev/null +++ b/tests/unit/Tag/DateTimeLocalFieldCest.php @@ -0,0 +1,22 @@ + + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagHelper; + +class DateTimeLocalFieldCest extends TagHelper +{ + protected $function = 'dateTimeLocalField'; + protected $inputType = 'datetime-local'; +} diff --git a/tests/unit/Tag/DisplayToCest.php b/tests/unit/Tag/DisplayToCest.php new file mode 100644 index 00000000000..ecfeccfbc3d --- /dev/null +++ b/tests/unit/Tag/DisplayToCest.php @@ -0,0 +1,65 @@ + + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class DisplayToCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: displayTo() + * + * @author Phalcon Team + * @since 2018-11-13 + */ + public function tagDisplayTo(UnitTester $I) + { + $I->wantToTest('Tag - displayTo()'); + + //Init Data + Tag::displayTo('city', 'Miramas'); + Tag::displayTo('country', 'France'); + Tag::displayTo('zipcode', '13140'); + + //check if exists + $I->assertTrue( + Tag::hasValue('city') + ); + $I->assertTrue( + Tag::hasValue('country') + ); + $I->assertTrue( + Tag::hasValue('zipcode') + ); + $I->assertFalse( + Tag::hasValue('area') + ); + + //Check value + $I->assertSame( + 'Miramas', + Tag::getValue('city') + ); + $I->assertSame( + 'France', + Tag::getValue('country') + ); + $I->assertSame( + '13140', + Tag::getValue('zipcode') + ); + } +} diff --git a/tests/unit/Tag/EmailFieldCest.php b/tests/unit/Tag/EmailFieldCest.php new file mode 100644 index 00000000000..ff7ae2c91ff --- /dev/null +++ b/tests/unit/Tag/EmailFieldCest.php @@ -0,0 +1,22 @@ + + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagHelper; + +class EmailFieldCest extends TagHelper +{ + protected $function = 'emailField'; + protected $inputType = 'email'; +} diff --git a/tests/unit/Tag/EndFormCest.php b/tests/unit/Tag/EndFormCest.php new file mode 100644 index 00000000000..74a1506e284 --- /dev/null +++ b/tests/unit/Tag/EndFormCest.php @@ -0,0 +1,35 @@ + + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class EndFormCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: endForm() + * + * @author Phalcon Team + * @since 2018-11-13 + */ + public function tagEndForm(UnitTester $I) + { + $I->wantToTest('Tag - endForm()'); + $expected = ''; + $actual = Tag::endForm(); + $I->assertSame($expected, $actual); + } +} diff --git a/tests/unit/Tag/FileFieldCest.php b/tests/unit/Tag/FileFieldCest.php new file mode 100644 index 00000000000..6c57463d1c2 --- /dev/null +++ b/tests/unit/Tag/FileFieldCest.php @@ -0,0 +1,22 @@ + + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagHelper; + +class FileFieldCest extends TagHelper +{ + protected $function = 'fileField'; + protected $inputType = 'file'; +} diff --git a/tests/unit/Tag/FormLegacyCest.php b/tests/unit/Tag/FormLegacyCest.php new file mode 100644 index 00000000000..4d114dc35ae --- /dev/null +++ b/tests/unit/Tag/FormLegacyCest.php @@ -0,0 +1,41 @@ + + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class FormLegacyCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: form() + * + * @author Phalcon Team + * @since 2020-02-22 + */ + public function tagForm(UnitTester $I) + { + $I->wantToTest('Tag - form()'); + + $options = [ + 'x_name', + 'class' => 'x_class', + ]; + + $expected = '
'; + $actual = Tag::formLegacy($options); + $I->assertSame($expected, $actual); + } +} diff --git a/tests/unit/Tag/FriendlyTitleCest.php b/tests/unit/Tag/FriendlyTitleCest.php new file mode 100644 index 00000000000..50563685267 --- /dev/null +++ b/tests/unit/Tag/FriendlyTitleCest.php @@ -0,0 +1,181 @@ + + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class FriendlyTitleCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: friendlyTitle() - string as a parameter and no + * separator + * + * @author Phalcon Team + * @since 2014-09-11 + */ + public function testFriendlyTitleStringParameterNoSeparator(UnitTester $I) + { + $options = 'This is a Test'; + $expected = 'this-is-a-test'; + $actual = Tag::friendlyTitle($options); + + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: friendlyTitle() - string as a parameter and a + * separator + * + * @author Phalcon Team + * @since 2014-09-11 + */ + public function testFriendlyTitleStringParameterSeparator(UnitTester $I) + { + $options = 'This is a Test'; + $expected = 'this_is_a_test'; + $actual = Tag::friendlyTitle($options, '_'); + + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: friendlyTitle() - string as a parameter lowercase + * + * @author Phalcon Team + * @since 2014-09-11 + */ + public function testFriendlyTitleStringParameterLowercase(UnitTester $I) + { + $options = 'This is a Test'; + $expected = 'this_is_a_test'; + $actual = Tag::friendlyTitle($options, '_', true); + + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: friendlyTitle() - string as a parameter uppercase + * + * @author Phalcon Team + * @since 2014-09-11 + */ + public function testFriendlyTitleStringParameterUppercase(UnitTester $I) + { + $options = 'This is a Test'; + $expected = 'This_is_a_Test'; + $actual = Tag::friendlyTitle($options, '_', false); + + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: friendlyTitle() - string as a parameter with + * replace as string + * + * @author Phalcon Team + * @since 2014-09-11 + */ + public function testFriendlyTitleStringParameterReplaceString(UnitTester $I) + { + $options = 'This is a Test'; + $expected = 'th_s_s_a_test'; + $actual = Tag::friendlyTitle($options, '_', true, 'i'); + + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: friendlyTitle() - string as a parameter with + * replace as array + * + * @author Phalcon Team + * @since 2014-09-11 + */ + public function testFriendlyTitleStringParameterReplaceArray(UnitTester $I) + { + $options = 'This is a Test'; + $expected = 't_s_s_a_test'; + $actual = Tag::friendlyTitle( + $options, + '_', + true, + ['i', 'h'] + ); + + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: friendlyTitle() - special characters and escaping + * + * @author Phalcon Team + * @since 2014-09-11 + */ + public function testFriendlyTitleWithSpecialCharactersAndEscaping(UnitTester $I) + { + $options = "Mess'd up --text-- just (to) stress /test/ ?our! " + . '`little` \\clean\\ url fun.ction!?-->'; + + $I->assertSame( + 'messd-up-text-just-to-stress-test-our-little-clean-url-function', + Tag::friendlyTitle($options) + ); + } + + /** + * Tests Phalcon\Tag :: friendlyTitle() - accented characters and replace + * string + * + * @author Phalcon Team + * @since 2014-09-11 + */ + public function testFriendlyTitleWithAccentedCharactersAndReplaceString(UnitTester $I) + { + $options = "Perché l'erba è verde?"; + + $I->assertSame( + 'perche-l-erba-e-verde', + Tag::friendlyTitle( + $options, + '-', + true, + "'" + ) + ); + } + + /** + * Tests Phalcon\Tag :: friendlyTitle() - accented characters and replace + * array + * + * @author Phalcon Team + * @since 2014-09-11 + */ + public function testFriendlyTitleWithAccentedCharactersAndReplaceArray(UnitTester $I) + { + $options = "Perché l'erba è verde?"; + + $I->assertSame( + 'P_rch_l_rb_v_rd', + Tag::friendlyTitle( + $options, + '_', + false, + ['e', 'a'] + ) + ); + } +} diff --git a/tests/unit/Tag/GetDocTypeCest.php b/tests/unit/Tag/GetDocTypeCest.php new file mode 100644 index 00000000000..455675c65e8 --- /dev/null +++ b/tests/unit/Tag/GetDocTypeCest.php @@ -0,0 +1,143 @@ + + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class GetDocTypeCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: getDocType() - 3.2 + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function testDoctypeSet32Final(UnitTester $I) + { + $this->runDoctypeTest($I, Tag::HTML32); + } + + + /** + * Tests Phalcon\Tag :: getDocType() - 4.01 Strict + * + * @author Phalcon Team + * @since 2014-09-04 + */ + public function testDoctypeSet401(UnitTester $I) + { + $this->runDoctypeTest($I, Tag::HTML401_STRICT); + } + + /** + * Tests Phalcon\Tag :: getDocType() - 4.01 Transitional + * + * @author Phalcon Team + * @since 2014-09-04 + */ + public function testDoctypeSet401Transitional(UnitTester $I) + { + $this->runDoctypeTest($I, Tag::HTML401_TRANSITIONAL); + } + + /** + * Tests Phalcon\Tag :: getDocType() - 4.01 Frameset + * + * @author Phalcon Team + * @since 2014-09-04 + */ + public function testDoctypeSet401Frameset(UnitTester $I) + { + $this->runDoctypeTest($I, Tag::HTML401_FRAMESET); + } + + /** + * Tests Phalcon\Tag :: getDocType() - 5 + * + * @author Phalcon Team + * @since 2014-09-04 + */ + public function testDoctypeSet5(UnitTester $I) + { + $this->runDoctypeTest($I, Tag::HTML5); + } + + /** + * Tests Phalcon\Tag :: getDocType() - 1.0 Strict + * + * @author Phalcon Team + * @since 2014-09-04 + */ + public function testDoctypeSet10Strict(UnitTester $I) + { + $this->runDoctypeTest($I, Tag::XHTML10_STRICT); + } + + /** + * Tests Phalcon\Tag :: getDocType() - 1.0 Transitional + * + * @author Phalcon Team + * @since 2014-09-04 + */ + public function testDoctypeSet10Transitional(UnitTester $I) + { + $this->runDoctypeTest($I, Tag::XHTML10_TRANSITIONAL); + } + + /** + * Tests Phalcon\Tag :: getDocType() - 1.0 Frameset + * + * @author Phalcon Team + * @since 2014-09-04 + */ + public function testDoctypeSet10Frameset(UnitTester $I) + { + $this->runDoctypeTest($I, Tag::XHTML10_FRAMESET); + } + + /** + * Tests Phalcon\Tag :: getDocType() - 1.1 + * + * @author Phalcon Team + * @since 2014-09-04 + */ + public function testDoctypeSet11(UnitTester $I) + { + $this->runDoctypeTest($I, Tag::XHTML11); + } + + /** + * Tests Phalcon\Tag :: getDocType() - 2.0 + * + * @author Phalcon Team + * @since 2014-09-04 + */ + public function testDoctypeSet20(UnitTester $I) + { + $this->runDoctypeTest($I, Tag::XHTML20); + } + + /** + * Tests Phalcon\Tag :: getDocType() - wrong setting + * + * @author Phalcon Team + * @since 2014-09-04 + */ + public function testDoctypeSetWrongParameter(UnitTester $I) + { + $this->runDoctypeTest($I, 99); + } +} diff --git a/tests/unit/Tag/GetEscaperCest.php b/tests/unit/Tag/GetEscaperCest.php new file mode 100644 index 00000000000..122a64a50cd --- /dev/null +++ b/tests/unit/Tag/GetEscaperCest.php @@ -0,0 +1,44 @@ + + * + * 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\Tag; + +use Phalcon\Html\Escaper; +use Phalcon\Html\Escaper\EscaperInterface; +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class GetEscaperCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: getEscaper() + * + * @param UnitTester $I + * + * @since 2018-11-13 + * + * @author Phalcon Team + */ + public function tagGetEscaper(UnitTester $I) + { + $I->wantToTest('Tag - getEscaper()'); + + $escaper = Tag::getEscaper([]); + $I->assertInstanceOf(Escaper::class, $escaper); + $I->assertInstanceOf(EscaperInterface::class, $escaper); + + $escaper = Tag::getEscaper(["escape" => false]); + $I->assertNull($escaper); + } +} diff --git a/tests/unit/Tag/GetEscaperServiceCest.php b/tests/unit/Tag/GetEscaperServiceCest.php new file mode 100644 index 00000000000..d8677e8a50e --- /dev/null +++ b/tests/unit/Tag/GetEscaperServiceCest.php @@ -0,0 +1,41 @@ + + * + * 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\Tag; + +use Phalcon\Html\Escaper; +use Phalcon\Html\Escaper\EscaperInterface; +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class GetEscaperServiceCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: getEscaperService() + * + * @param UnitTester $I + * + * @since 2018-11-13 + * + * @author Phalcon Team + */ + public function tagGetEscaperService(UnitTester $I) + { + $I->wantToTest('Tag - getEscaperService()'); + + $escaper = Tag::getEscaperService(); + $I->assertInstanceOf(Escaper::class, $escaper); + $I->assertInstanceOf(EscaperInterface::class, $escaper); + } +} diff --git a/tests/unit/Tag/GetHasValueCest.php b/tests/unit/Tag/GetHasValueCest.php new file mode 100644 index 00000000000..c2861a2692d --- /dev/null +++ b/tests/unit/Tag/GetHasValueCest.php @@ -0,0 +1,66 @@ + + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +use function uniqid; + +class GetHasValueCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: getValue()/hasValue() + * + * @author Phalcon Team + * @since 2020-02-22 + */ + public function tagGetHasValue(UnitTester $I) + { + $I->wantToTest('Tag - getValue()/hasValue()'); + + $post = $_POST; + + $key = uniqid('key-'); + $value = uniqid('val-'); + + $actual = Tag::getValue($key, ['value' => $value]); + $I->assertSame($value, $actual); + + $key = uniqid('key-'); + $value = uniqid('val-'); + + Tag::setDefault($key, $value); + + $key = uniqid('key-'); + $value = uniqid('val-'); + + $_POST = [ + $key => $value, + ]; + + $actual = Tag::getValue($key, []); + $I->assertSame($value, $actual); + + $_POST = []; + + $key = uniqid('key-'); + + $actual = Tag::getValue($key, []); + $I->assertNull($actual); + + $_POST = $post; + } +} diff --git a/tests/unit/Tag/GetSetDICest.php b/tests/unit/Tag/GetSetDICest.php new file mode 100644 index 00000000000..1c70ce763c8 --- /dev/null +++ b/tests/unit/Tag/GetSetDICest.php @@ -0,0 +1,49 @@ + + * + * 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\Tag; + +use Phalcon\Di\Di; +use Phalcon\Tag; +use UnitTester; + +class GetSetDICest +{ + /** + * Tests Phalcon\Tag :: getDI() / setDI() + * + * @author Jeremy PASTOURET + * @since 2019-12-07 + */ + public function tagGetSetDI(UnitTester $I) + { + $I->wantToTest('Tag - getDI() / setDI()'); + + $container = new Di(); + + $tag = new Tag(); + + $tag->setDI($container); + + $expected = $container; + $actual = $tag->getDI(); + $I->assertSame($expected, $actual); + + $class = Di::class; + $actual = $tag->getDI(); + $I->assertInstanceOf($class, $actual); + + $expected = $container; + $I->assertSame($expected, $actual); + } +} diff --git a/tests/unit/Tag/GetSetTitleSeparatorCest.php b/tests/unit/Tag/GetSetTitleSeparatorCest.php new file mode 100644 index 00000000000..bdb42d99699 --- /dev/null +++ b/tests/unit/Tag/GetSetTitleSeparatorCest.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. + */ + +declare(strict_types=1); + +namespace Phalcon\Tests\Unit\Tag; + +use Phalcon\Tag; +use UnitTester; + +class GetSetTitleSeparatorCest +{ + /** + * Tests Phalcon\Tag :: getTitleSeparator()/setTitleSeparator() + * + * @author Phalcon Team + * @since 2012-09-05 + * @since 2018-11-13 + */ + public function tagGetSetTitleSeparator(UnitTester $I) + { + $I->wantToTest('Tag - getTitleSeparator()/setTitleSeparator()'); + Tag::resetInput(); + Tag::setTitleSeparator('-'); + + $expected = '-'; + $actual = Tag::getTitleSeparator(); + $I->assertSame($expected, $actual); + } +} diff --git a/tests/unit/Tag/GetTitleCest.php b/tests/unit/Tag/GetTitleCest.php new file mode 100644 index 00000000000..5e8ec318163 --- /dev/null +++ b/tests/unit/Tag/GetTitleCest.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. + */ + +declare(strict_types=1); + +namespace Phalcon\Tests\Unit\Tag; + +use Phalcon\Tag; +use UnitTester; + +class GetTitleCest +{ + /** + * Tests Phalcon\Tag :: getTitle() - with malicious code + * + * @issue https://github.com/phalcon/cphalcon/issues/11185 + * @author Phalcon Team + * @since 2016-01-13 + */ + public function tagGetTitleWithMaliciousContent(UnitTester $I) + { + $I->wantToTest('Tag - getTitle() - with malicious code'); + + Tag::resetInput(); + + Tag::setTitle( + "Hello " + ); + + $I->assertSame( + 'Hello </title><script>alert('Got your nose!');</script><title>', + Tag::getTitle() + ); + } +} diff --git a/tests/unit/Tag/GetUrlServiceCest.php b/tests/unit/Tag/GetUrlServiceCest.php new file mode 100644 index 00000000000..8e9dd587685 --- /dev/null +++ b/tests/unit/Tag/GetUrlServiceCest.php @@ -0,0 +1,39 @@ +<?php + +/** + * This file is part of the Phalcon Framework. + * + * (c) Phalcon Team <team@phalcon.io> + * + * 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\Tag; + +use Phalcon\Mvc\Url; +use Phalcon\Mvc\Url\UrlInterface; +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class GetUrlServiceCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: getUrlService() + * + * @author Phalcon Team <team@phalcon.io> + * @since 2018-11-13 + */ + public function tagGetUrlService(UnitTester $I) + { + $I->wantToTest('Tag - getUrlService()'); + + $url = Tag::getUrlService(); + + $I->assertInstanceOf(Url::class, $url); + $I->assertInstanceOf(UrlInterface::class, $url); + } +} diff --git a/tests/unit/Tag/HiddenFieldCest.php b/tests/unit/Tag/HiddenFieldCest.php new file mode 100644 index 00000000000..2fb749655a7 --- /dev/null +++ b/tests/unit/Tag/HiddenFieldCest.php @@ -0,0 +1,22 @@ +<?php + +/** + * This file is part of the Phalcon Framework. + * + * (c) Phalcon Team <team@phalcon.io> + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagHelper; + +class HiddenFieldCest extends TagHelper +{ + protected $function = 'hiddenField'; + protected $inputType = 'hidden'; +} diff --git a/tests/unit/Tag/ImageCest.php b/tests/unit/Tag/ImageCest.php new file mode 100644 index 00000000000..8f1c01c97ae --- /dev/null +++ b/tests/unit/Tag/ImageCest.php @@ -0,0 +1,305 @@ +<?php + +/** + * This file is part of the Phalcon Framework. + * + * (c) Phalcon Team <team@phalcon.io> + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class ImageCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: image() - string as a parameter + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageStringParameter(UnitTester $I) + { + $I->wantToTest('Tag :: image() - string as a parameter'); + + $options = 'img/hello.gif'; + $expected = '<img src="/img/hello.gif"'; + + $this->testFieldParameter($I, 'image', $options, $expected); + $this->testFieldParameter($I, 'image', $options, $expected, true); + } + + /** + * Tests Phalcon\Tag :: image() - array as a parameter + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageArrayParameter(UnitTester $I) + { + $I->wantToTest('Tag :: image() - array as a parameter'); + + $options = [ + 'img/hello.gif', + 'class' => 'x_class', + ]; + $expected = '<img src="/img/hello.gif" class="x_class"'; + + $this->testFieldParameter($I, 'image', $options, $expected); + $this->testFieldParameter($I, 'image', $options, $expected, true); + } + + /** + * Tests Phalcon\Tag :: image() - array as a parameters and src in it + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageArrayParameterWithSrc(UnitTester $I) + { + $I->wantToTest('Tag :: image() - array as a parameters and src in it'); + + $options = [ + 'img/hello.gif', + 'src' => 'img/goodbye.gif', + 'class' => 'x_class', + ]; + $expected = '<img src="/img/goodbye.gif" class="x_class"'; + + $this->testFieldParameter($I, 'image', $options, $expected); + $this->testFieldParameter($I, 'image', $options, $expected, true); + } + + /** + * Tests Phalcon\Tag :: image() - name and no src in parameter + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageArrayParameterWithNameNoSrc(UnitTester $I) + { + $I->wantToTest('Tag :: image() - name and no src in parameter'); + + $options = [ + 'img/hello.gif', + 'class' => 'x_class', + ]; + $expected = '<img src="/img/hello.gif" class="x_class"'; + + $this->testFieldParameter($I, 'image', $options, $expected); + $this->testFieldParameter($I, 'image', $options, $expected, true); + } + + /** + * Tests Phalcon\Tag :: image() - setDefault + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageWithSetDefault(UnitTester $I) + { + $I->wantToTest('Tag :: image() - setDefault()'); + + $options = [ + 'img/hello.gif', + 'class' => 'x_class', + ]; + $expected = '<img src="/img/hello.gif" class="x_class"'; + + $this->testFieldParameter($I, 'image', $options, $expected, false, 'setDefault'); + $this->testFieldParameter($I, 'image', $options, $expected, true, 'setDefault'); + } + + /** + * Tests Phalcon\Tag :: image() - displayTo + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageWithDisplayTo(UnitTester $I) + { + $I->wantToTest('Tag :: image() - displayTo()'); + + $options = [ + 'img/hello.gif', + 'class' => 'x_class', + ]; + $expected = '<img src="/img/hello.gif" class="x_class"'; + + $this->testFieldParameter($I, 'image', $options, $expected, false, 'displayTo'); + $this->testFieldParameter($I, 'image', $options, $expected, true, 'displayTo'); + } + + /** + * Tests Phalcon\Tag :: image() - setDefault and element not present + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageWithSetDefaultElementNotPresent(UnitTester $I) + { + $I->wantToTest('Tag :: image() - setDefault() and element not present'); + + $options = [ + 'img/hello.gif', + 'class' => 'x_class', + ]; + $expected = '<img src="/img/hello.gif" class="x_class"'; + + $this->testFieldParameter($I, 'image', $options, $expected, false, 'setDefault'); + $this->testFieldParameter($I, 'image', $options, $expected, true, 'setDefault'); + } + + /** + * Tests Phalcon\Tag :: image() - displayTo and element not present + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageWithDisplayToElementNotPresent(UnitTester $I) + { + $I->wantToTest('Tag :: image() - displayTo() and element not present'); + + $options = [ + 'img/hello.gif', + 'class' => 'x_class', + ]; + $expected = '<img src="/img/hello.gif" class="x_class"'; + + $this->testFieldParameter($I, 'image', $options, $expected, false, 'displayTo'); + $this->testFieldParameter($I, 'image', $options, $expected, true, 'displayTo'); + } + + /** + * Tests Phalcon\Tag :: image() - string parameter and local link + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageStringParameterLocalLink(UnitTester $I) + { + $I->wantToTest('Tag :: image() - string parameter and local link'); + + $options = 'img/hello.gif'; + $expected = '<img src="/img/hello.gif" />'; + + Tag::setDocType(Tag::XHTML10_STRICT); + $actual = Tag::image($options, true); + + $I->assertSame($expected, $actual); + + $options = 'img/hello.gif'; + $expected = '<img src="/img/hello.gif">'; + + Tag::setDocType(Tag::HTML5); + $actual = Tag::image($options, true); + + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: image() - string parameter and remote link + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageStringParameterRemoteLink(UnitTester $I) + { + $I->wantToTest('Tag :: image() - string parameter and remote link'); + + $options = 'http://phalcon.io/img/hello.gif'; + $expected = '<img src="http://phalcon.io/img/hello.gif" />'; + + Tag::setDocType(Tag::XHTML10_STRICT); + $actual = Tag::image($options, false); + + $I->assertSame($expected, $actual); + + $options = 'http://phalcon.io/img/hello.gif'; + $expected = '<img src="http://phalcon.io/img/hello.gif">'; + + Tag::setDocType(Tag::HTML5); + $actual = Tag::image($options, false); + + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: image() - array parameter and local link + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageArrayParameterLocalLink(UnitTester $I) + { + $I->wantToTest('Tag :: image() - array parameter and local link'); + + $options = [ + 'img/hello.gif', + 'alt' => 'Hello', + ]; + $expected = '<img src="/img/hello.gif" alt="Hello" />'; + + Tag::setDocType(Tag::XHTML10_STRICT); + $actual = Tag::image($options, true); + + $I->assertSame($expected, $actual); + + $options = [ + 'img/hello.gif', + 'alt' => 'Hello', + ]; + $expected = '<img src="/img/hello.gif" alt="Hello">'; + + Tag::setDocType(Tag::HTML5); + $actual = Tag::image($options, true); + + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: image() - array parameter and remote link + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageArrayParameterRemoteLink(UnitTester $I) + { + $I->wantToTest('Tag :: image() - array parameter and remote link'); + + $options = [ + 'http://phalcon.io/img/hello.gif', + 'alt' => 'Hello', + ]; + + Tag::setDocType( + Tag::XHTML10_STRICT + ); + + $I->assertSame( + '<img src="http://phalcon.io/img/hello.gif" alt="Hello" />', + Tag::image($options, false) + ); + + $options = [ + 'http://phalcon.io/img/hello.gif', + 'alt' => 'Hello', + ]; + + Tag::setDocType( + Tag::HTML5 + ); + + $I->assertSame( + '<img src="http://phalcon.io/img/hello.gif" alt="Hello">', + Tag::image($options, false) + ); + } +} diff --git a/tests/unit/Tag/ImageInputCest.php b/tests/unit/Tag/ImageInputCest.php new file mode 100644 index 00000000000..4277ca69a67 --- /dev/null +++ b/tests/unit/Tag/ImageInputCest.php @@ -0,0 +1,370 @@ +<?php + +/** + * This file is part of the Phalcon Framework. + * + * (c) Phalcon Team <team@phalcon.io> + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class ImageInputCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: imageInput() - string as a parameter + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageInputStringParameter(UnitTester $I) + { + $I->wantToTest('Tag :: imageInput() - string as a parameter'); + $options = 'x_name'; + $expected = '<input type="image" value="x_name"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + false + ); + + $options = 'x_name'; + $expected = '<input type="image" value="x_name"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + true + ); + } + + /** + * Tests Phalcon\Tag :: imageInput() - array as a parameter + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageInputArrayParameter(UnitTester $I) + { + $I->wantToTest('Tag :: imageInput() - array as a parameter'); + $options = [ + 'x_name', + 'class' => 'x_class', + ]; + $expected = '<input type="image" value="x_name" ' + . 'class="x_class"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + false + ); + + $options = [ + 'x_name', + 'class' => 'x_class', + ]; + $expected = '<input type="image" value="x_name" ' + . 'class="x_class"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + true + ); + } + + /** + * Tests Phalcon\Tag :: imageInput() - array as a parameters and id in it + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageInputArrayParameterWithId(UnitTester $I) + { + $I->wantToTest('Tag :: imageInput() - array as a parameters and id in it'); + $options = [ + 'x_name', + 'id' => 'x_id', + 'class' => 'x_class', + 'size' => '10', + ]; + $expected = '<input type="image" id="x_id" value="x_name" ' + . 'class="x_class" size="10"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + true + ); + + $options = [ + 'x_name', + 'id' => 'x_id', + 'class' => 'x_class', + 'size' => '10', + ]; + $expected = '<input type="image" id="x_id" value="x_name" ' + . 'class="x_class" size="10"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + true + ); + } + + /** + * Tests Phalcon\Tag :: imageInput() - name and no id in parameter + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageInputArrayParameterWithNameNoId(UnitTester $I) + { + $I->wantToTest('Tag :: imageInput() - name and no id in parameter'); + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + $expected = '<input type="image" name="x_other" ' + . 'value="x_name" class="x_class" size="10"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + false + ); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + $expected = '<input type="image" name="x_other" ' + . 'value="x_name" class="x_class" size="10"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + true + ); + } + + /** + * Tests Phalcon\Tag :: imageInput() - setDefault + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageInputWithSetDefault(UnitTester $I) + { + $I->wantToTest('Tag :: imageInput() - setDefault()'); + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + $expected = '<input type="image" name="x_other" ' + . 'value="x_name" class="x_class" size="10"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + false, + 'setDefault' + ); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + $expected = '<input type="image" ' + . 'name="x_other" value="x_name" class="x_class" ' + . 'size="10"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + true, + 'setDefault' + ); + } + + /** + * Tests Phalcon\Tag :: imageInput() - displayTo + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageInputWithDisplayTo(UnitTester $I) + { + $I->wantToTest('Tag :: imageInput() - displayTo()'); + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + $expected = '<input type="image" ' + . 'name="x_other" value="x_name" class="x_class" ' + . 'size="10"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + false, + 'displayTo' + ); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + $expected = '<input type="image" ' + . 'name="x_other" value="x_name" class="x_class" ' + . 'size="10"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + true, + 'displayTo' + ); + } + + /** + * Tests Phalcon\Tag :: imageInput() - setDefault and element not present + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageInputWithSetDefaultElementNotPresent(UnitTester $I) + { + $I->wantToTest('Tag :: imageInput() - setDefault() and element not present'); + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + $expected = '<input type="image" ' + . 'name="x_other" value="x_name" class="x_class" ' + . 'size="10"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + false, + 'setDefault' + ); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + $expected = '<input type="image" ' + . 'name="x_other" value="x_name" class="x_class" ' + . 'size="10"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + true, + 'setDefault' + ); + } + + /** + * Tests Phalcon\Tag :: imageInput() - displayTo and element not present + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-05 + */ + public function tagImageInputWithDisplayToElementNotPresent(UnitTester $I) + { + $I->wantToTest('Tag :: imageInput() - displayTo() and element not present'); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = '<input type="image" name="x_other" value="x_name" class="x_class" size="10"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + false, + 'displayTo' + ); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = '<input type="image" name="x_other" value="x_name" class="x_class" size="10"'; + + $this->testFieldParameter( + $I, + 'imageInput', + $options, + $expected, + true, + 'displayTo' + ); + } +} diff --git a/tests/unit/Tag/JavascriptIncludeCest.php b/tests/unit/Tag/JavascriptIncludeCest.php new file mode 100644 index 00000000000..42a8ede2aaf --- /dev/null +++ b/tests/unit/Tag/JavascriptIncludeCest.php @@ -0,0 +1,132 @@ +<?php + +/** + * This file is part of the Phalcon Framework. + * + * (c) Phalcon Team <team@phalcon.io> + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class JavascriptIncludeCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: javascriptInclude() - string as a parameter local + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-29 + */ + public function tagJavascriptIncludeLocal(UnitTester $I) + { + $I->wantToTest('Tag - javascriptInclude() - string as a parameter local'); + + $options = 'js/phalcon.js'; + + Tag::setDocType( + Tag::HTML5 + ); + + $I->assertSame( + '<script src="/js/phalcon.js"></script>' . PHP_EOL, + Tag::javascriptInclude($options) + ); + } + + /** + * Tests Phalcon\Tag :: javascriptInclude() - array as a parameter local + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-29 + */ + public function tagJavascriptIncludeWithArrayLocal(UnitTester $I) + { + $I->wantToTest('Tag - javascriptInclude()'); + + $options = ['js/phalcon.js']; + + Tag::setDocType( + Tag::HTML5 + ); + + $I->assertSame( + '<script src="/js/phalcon.js"></script>' . PHP_EOL, + Tag::javascriptInclude($options) + ); + } + + /** + * Tests Phalcon\Tag :: javascriptInclude() - remote link + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-29 + */ + public function tagJavascriptIncludeRemote(UnitTester $I) + { + $I->wantToTest('Tag - javascriptInclude() - remote link'); + + $options = 'http://my.local.com/js/phalcon.js'; + + Tag::setDocType( + Tag::HTML5 + ); + + $I->assertSame( + '<script src="http://my.local.com/js/phalcon.js"></script>' . PHP_EOL, + Tag::javascriptInclude($options, false) + ); + } + + /** + * Tests Phalcon\Tag :: javascriptInclude() - array parameter for a remote + * link + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-29 + */ + public function tagJavascriptIncludeWithArrayRemote(UnitTester $I) + { + $I->wantToTest('Tag - javascriptInclude() - array parameter for a remote'); + + $options = ['http://my.local.com/js/phalcon.js']; + + Tag::setDocType(Tag::HTML5); + + $I->assertSame( + '<script src="http://my.local.com/js/phalcon.js"></script>' . PHP_EOL, + Tag::javascriptInclude($options, false) + ); + } + + /** + * Tests Phalcon\Tag :: javascriptInclude() - HTML5 + * + * @issue https://github.com/phalcon/cphalcon/issues/13341 + * + * @author Phalcon Team <team@phalcon.io> + * @since 2018-12-22 + */ + public function tagJavascriptIncludeHtml5(UnitTester $I) + { + $I->wantToTest('Tag - javascript() - HTML5'); + + $url = 'js/phalcon.js'; + + Tag::setDocType( + Tag::HTML32 + ); + + $I->assertSame( + '<script type="text/javascript" src="/js/phalcon.js"></script>' . PHP_EOL, + Tag::javascriptInclude($url) + ); + } +} diff --git a/tests/unit/Tag/LinkToCest.php b/tests/unit/Tag/LinkToCest.php new file mode 100644 index 00000000000..8a6a6494caf --- /dev/null +++ b/tests/unit/Tag/LinkToCest.php @@ -0,0 +1,240 @@ +<?php + +/** + * This file is part of the Phalcon Framework. + * + * (c) Phalcon Team <team@phalcon.io> + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class LinkToCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: linkTo() - string as URL and name + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-29 + */ + public function tagLinkToWithStringAsURLAndName(UnitTester $I) + { + $I->wantToTest('Tag - linkTo() - string as URL and name'); + + $url = 'x_url'; + $name = 'x_name'; + + $I->assertSame( + '<a href="/x_url">x_name</a>', + Tag::linkTo($url, $name) + ); + } + + /** + * Tests Phalcon\Tag :: linkTo() - string as URL and name + * + * @issue https://github.com/phalcon/cphalcon/issues/2002 + * @author Phalcon Team <team@phalcon.io> + * @author Dreamszhu <dreamsxin@qq.com> + * @since 2014-03-10 + */ + public function tagLinkToWithQueryParam(UnitTester $I) + { + $I->wantToTest('Tag - linkTo() - string as URL and name'); + + $actual = Tag::linkTo( + [ + 'signup/register', + 'Register Here!', + 'class' => 'btn-primary', + 'query' => [ + 'from' => 'github', + 'token' => '123456', + ], + ] + ); + + $I->assertSame( + '<a href="/signup/register?from=github&token=123456" class="btn-primary">Register Here!</a>', + $actual + ); + } + + /** + * Tests Phalcon\Tag :: linkTo() - empty string as URL and string as name + * parameter + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-29 + */ + public function tagLinkToWithEmptyStringAsURLAndStringAsName(UnitTester $I) + { + $I->wantToTest('Tag - linkTo() - empty string as URL and string as name parameter'); + + $url = ''; + $name = 'x_name'; + + $I->assertSame( + '<a href="/">x_name</a>', + Tag::linkTo($url, $name) + ); + } + + /** + * Tests Phalcon\Tag :: linkTo() - array as a parameter + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-29 + */ + public function tagLinkToArrayParameter(UnitTester $I) + { + $I->wantToTest('Tag - linkTo() - array as a parameter'); + + $options = [ + 'x_url', + 'x_name', + ]; + + $I->assertSame( + '<a href="/x_url">x_name</a>', + Tag::linkTo($options) + ); + } + + /** + * Tests Phalcon\Tag :: linkTo() - named array as a parameter + * + * @author Phalcon Team <team@phalcon.io> + * @since 2014-09-29 + */ + public function tagLinkToNamedArrayParameter(UnitTester $I) + { + $I->wantToTest('Tag - linkTo() - named array as a parameter'); + + $options = [ + 'action' => 'x_url', + 'text' => 'x_name', + 'class' => 'x_class', + ]; + + $I->assertSame( + '<a href="/x_url" class="x_class">x_name</a>', + Tag::linkTo($options) + ); + } + + /** + * Tests Phalcon\Tag :: linkTo() - complex local URL + * + * @issue https://github.com/phalcon/cphalcon/issues/1679 + * @author Phalcon Team <team@phalcon.io> + * @author Dreamszhu <dreamsxin@qq.com> + * @since 2014-09-29 + */ + public function tagLinkToWithComplexLocalUrl(UnitTester $I) + { + $I->wantToTest('Tag - linkTo() - complex local URL'); + + Tag::resetInput(); + + $url = 'x_action/x_param'; + $name = 'x_name'; + + $I->assertSame( + '<a href="/x_action/x_param">x_name</a>', + Tag::linkTo($url, $name) + ); + + Tag::resetInput(); + + $options = [ + 'x_action/x_param', + 'x_name', + ]; + + $I->assertSame( + '<a href="/x_action/x_param">x_name</a>', + Tag::linkTo($options) + ); + + Tag::resetInput(); + + $options = [ + 'x_action/x_param', + 'x_name', + 'class' => 'x_class', + ]; + + $I->assertSame( + '<a href="/x_action/x_param" class="x_class">x_name</a>', + Tag::linkTo($options) + ); + } + + /** + * Tests Phalcon\Tag :: linkTo() - complex remote URL + * + * @issue https://github.com/phalcon/cphalcon/issues/1679 + * @author Phalcon Team <team@phalcon.io> + * @author Dreamszhu <dreamsxin@qq.com> + * @since 2014-09-29 + */ + public function tagLinkToWithComplexRemoteUrl(UnitTester $I) + { + $I->wantToTest('Tag - linkTo() - complex remote URL'); + + Tag::resetInput(); + + $url = 'http://phalcon.io/en/'; + $name = 'x_name'; + + $I->assertSame( + '<a href="http://phalcon.io/en/">x_name</a>', + Tag::linkTo($url, $name, false) + ); + + Tag::resetInput(); + + $options = [ + 'http://phalcon.io/en/', + 'x_name', + false, + ]; + + $I->assertSame( + '<a href="http://phalcon.io/en/">x_name</a>', + Tag::linkTo($options) + ); + + Tag::resetInput(); + + $options = [ + 'http://phalcon.io/en/', + 'text' => 'x_name', + 'local' => false, + ]; + + $I->assertSame( + '<a href="http://phalcon.io/en/">x_name</a>', + Tag::linkTo($options) + ); + + Tag::resetInput(); + + $url = 'mailto:someone@phalcon.io'; + $name = 'someone@phalcon.io'; + + $I->assertSame( + '<a href="mailto:someone@phalcon.io">someone@phalcon.io</a>', + Tag::linkTo($url, $name, false) + ); + } +} diff --git a/tests/unit/Tag/MonthFieldCest.php b/tests/unit/Tag/MonthFieldCest.php new file mode 100644 index 00000000000..a65d1337a30 --- /dev/null +++ b/tests/unit/Tag/MonthFieldCest.php @@ -0,0 +1,22 @@ +<?php + +/** + * This file is part of the Phalcon Framework. + * + * (c) Phalcon Team <team@phalcon.io> + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagHelper; + +class MonthFieldCest extends TagHelper +{ + protected $function = 'monthField'; + protected $inputType = 'month'; +} diff --git a/tests/unit/Tag/NumericFieldCest.php b/tests/unit/Tag/NumericFieldCest.php new file mode 100644 index 00000000000..1d3bdf242b8 --- /dev/null +++ b/tests/unit/Tag/NumericFieldCest.php @@ -0,0 +1,22 @@ +<?php + +/** + * This file is part of the Phalcon Framework. + * + * (c) Phalcon Team <team@phalcon.io> + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagHelper; + +class NumericFieldCest extends TagHelper +{ + protected $function = 'numericField'; + protected $inputType = 'number'; +} diff --git a/tests/unit/Tag/PasswordFieldCest.php b/tests/unit/Tag/PasswordFieldCest.php new file mode 100644 index 00000000000..452302e1c07 --- /dev/null +++ b/tests/unit/Tag/PasswordFieldCest.php @@ -0,0 +1,22 @@ +<?php + +/** + * This file is part of the Phalcon Framework. + * + * (c) Phalcon Team <team@phalcon.io> + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagHelper; + +class PasswordFieldCest extends TagHelper +{ + protected $function = 'passwordField'; + protected $inputType = 'password'; +} diff --git a/tests/unit/Tag/PrependTitleCest.php b/tests/unit/Tag/PrependTitleCest.php new file mode 100644 index 00000000000..8d573a9ad68 --- /dev/null +++ b/tests/unit/Tag/PrependTitleCest.php @@ -0,0 +1,191 @@ +<?php + +/** + * This file is part of the Phalcon Framework. + * + * (c) Phalcon Team <team@phalcon.io> + * + * 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\Tag; + +use Phalcon\Tag; +use UnitTester; + +class PrependTitleCest +{ + /** + * Tests Phalcon\Tag :: prependTitle() + * + * @author Phalcon Team <team@phalcon.io> + * @since 2012-09-05 + */ + public function tagPrependTitle(UnitTester $I) + { + $I->wantToTest('Tag - prependTitle()'); + + Tag::resetInput(); + + Tag::setTitle('Title'); + + Tag::prependTitle('Class'); + + $I->assertSame( + 'Title', + Tag::getTitle(false, false) + ); + + $I->assertSame( + 'ClassTitle', + Tag::getTitle(true, false) + ); + + $I->assertSame( + '<title>ClassTitle' . PHP_EOL, + Tag::renderTitle() + ); + } + + /** + * Tests Phalcon\Tag :: prependTitle() - separator + * + * @author Phalcon Team + * @since 2012-09-05 + */ + public function tagPrependTitleSeparator(UnitTester $I) + { + $I->wantToTest('Tag - prependTitle() - separator'); + + Tag::resetInput(); + + Tag::setTitle('Title'); + Tag::setTitleSeparator('|'); + + Tag::prependTitle('Class'); + + $I->assertSame( + 'Title', + Tag::getTitle(false, false) + ); + + $I->assertSame( + 'Class|Title', + Tag::getTitle(true, false) + ); + + $I->assertSame( + 'Class|Title' . PHP_EOL, + Tag::renderTitle() + ); + } + + /** + * Tests Phalcon\Tag :: prependTitle() - double call + * + * @author Phalcon Team + * @since 2012-09-05 + */ + public function tagPrependTitleDoubleCall(UnitTester $I) + { + $I->wantToTest('Tag - prependTitle() - double call'); + + Tag::resetInput(); + + Tag::setTitle('Main'); + Tag::setTitleSeparator(' - '); + + Tag::prependTitle('Category'); + Tag::prependTitle('Title'); + + $I->assertSame( + 'Main', + Tag::getTitle(false, false) + ); + + $I->assertSame( + 'Title - Category - Main', + Tag::getTitle(true, false) + ); + + $I->assertSame( + 'Title - Category - Main' . PHP_EOL, + Tag::renderTitle() + ); + } + + /** + * Tests Phalcon\Tag :: prependTitle() - array + * + * @author Phalcon Team + * @since 2012-09-05 + */ + public function tagPrependTitleArray(UnitTester $I) + { + $I->wantToTest('Tag - prependTitle() - array'); + + Tag::resetInput(); + + Tag::setTitle('Main'); + Tag::setTitleSeparator(' - '); + + Tag::prependTitle( + ['Category', 'Title'] + ); + + $I->assertSame( + 'Main', + Tag::getTitle(false, false) + ); + + $I->assertSame( + 'Title - Category - Main', + Tag::getTitle(true, false) + ); + + $I->assertSame( + 'Title - Category - Main' . PHP_EOL, + Tag::renderTitle() + ); + } + + /** + * Tests Phalcon\Tag :: prependTitle() - empty array + * + * @author Phalcon Team + * @since 2012-09-05 + */ + public function tagPrependTitleEmptyArray(UnitTester $I) + { + $I->wantToTest('Tag - prependTitle() - empty array'); + + Tag::resetInput(); + + Tag::setTitle('Main'); + Tag::setTitleSeparator(' - '); + + Tag::prependTitle('Category'); + + Tag::prependTitle( + [] + ); + + $I->assertSame( + 'Main', + Tag::getTitle(false, false) + ); + + $I->assertSame( + 'Main', + Tag::getTitle(true, false) + ); + + $I->assertSame( + 'Main' . PHP_EOL, + Tag::renderTitle() + ); + } +} diff --git a/tests/unit/Tag/RadioFieldCest.php b/tests/unit/Tag/RadioFieldCest.php new file mode 100644 index 00000000000..b6ba3c82cf3 --- /dev/null +++ b/tests/unit/Tag/RadioFieldCest.php @@ -0,0 +1,44 @@ + + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class RadioFieldCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: radioField() + * + * @author Phalcon Team + * @since 2018-11-13 + */ + public function testRadioField(UnitTester $I) + { + $I->wantToTest('Tag - radioField()'); + + $options = [ + 'x_name', + 'id' => 'x_id', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = ''; + $actual = Tag::radioField($options); + $I->assertSame($expected, $actual); + } +} diff --git a/tests/unit/Tag/RangeFieldCest.php b/tests/unit/Tag/RangeFieldCest.php new file mode 100644 index 00000000000..129b9f77223 --- /dev/null +++ b/tests/unit/Tag/RangeFieldCest.php @@ -0,0 +1,22 @@ + + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagHelper; + +class RangeFieldCest extends TagHelper +{ + protected $function = 'rangeField'; + protected $inputType = 'range'; +} diff --git a/tests/unit/Tag/RenderAttributesCest.php b/tests/unit/Tag/RenderAttributesCest.php new file mode 100644 index 00000000000..7f3e4472426 --- /dev/null +++ b/tests/unit/Tag/RenderAttributesCest.php @@ -0,0 +1,41 @@ + + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class RenderAttributesCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: renderAttributes() + * + * @author Phalcon Team + * @since 2018-11-13 + */ + public function testRenderAttributes(UnitTester $I) + { + $options = [ + 'x_name', + 'id' => 'x_id', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = 'password id="x_id" class="x_class" size="10"'; + $actual = Tag::renderAttributes("password", $options); + $I->assertSame($expected, $actual); + } +} diff --git a/tests/unit/Tag/RenderTitleCest.php b/tests/unit/Tag/RenderTitleCest.php new file mode 100644 index 00000000000..de60c344aaa --- /dev/null +++ b/tests/unit/Tag/RenderTitleCest.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. + */ + +declare(strict_types=1); + +namespace Phalcon\Tests\Unit\Tag; + +use Phalcon\Tag; +use UnitTester; + +class RenderTitleCest +{ + /** + * Tests Phalcon\Tag :: renderTitle() - with malicious code + * + * @author Phalcon Team + * @since 2018-11-01 + */ + public function tatRenderTitleWithMaliciousContent(UnitTester $I) + { + $I->wantToTest('Tag - renderTitle() - with malicious code'); + + Tag::resetInput(); + + $value = "Hello "; + + Tag::setTitle($value); + + $I->assertSame( + '<title>Hello </title><script>alert('' . + 'Got your nose!');</script><title>' . PHP_EOL, + Tag::renderTitle() + ); + } +} diff --git a/tests/unit/Tag/ResetInputCest.php b/tests/unit/Tag/ResetInputCest.php new file mode 100644 index 00000000000..d8eef3a7e6d --- /dev/null +++ b/tests/unit/Tag/ResetInputCest.php @@ -0,0 +1,134 @@ + + * + * 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\Tag; + +use Phalcon\Tag; +use UnitTester; + +class ResetInputCest +{ + /** + * Tests Phalcon\Tag :: resetInput() + * + * Note: The Tag::resetInput should not clear $_POST data. + * + * @issue https://github.com/phalcon/cphalcon/issues/11319 + * @issue https://github.com/phalcon/cphalcon/issues/12099 + * @author Phalcon Team + * @since 2016-01-20 + */ + public function tagResetInputShouldNotClearPOST(UnitTester $I) + { + $I->wantToTest('Tag - resetInput() - should not clear POST data'); + + $_POST = [ + 'a' => '1', + 'b' => '2', + ]; + + Tag::resetInput(); + + $I->assertSame( + [ + 'a' => '1', + 'b' => '2', + ], + $_POST + ); + } + + /** + * Tests Phalcon\Tag :: resetInput() - setDefault + * + * @issue https://github.com/phalcon/cphalcon/issues/53 + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagResetInputSetDefault(UnitTester $I) + { + $I->wantToTest('Tag - resetInput() - setDefault()'); + + Tag::setDocType( + Tag::XHTML10_STRICT + ); + + $options = 'x_name'; + $expected = ''; + + Tag::setDefault('x_name', 'x_other'); + + $actual = Tag::textField($options); + + Tag::resetInput(); + + $I->assertSame($expected, $actual); + + $expected = ''; + $actual = Tag::textField($options); + $I->assertSame($expected, $actual); + + Tag::setDocType( + Tag::HTML5 + ); + + $options = 'x_name'; + $expected = ''; + + Tag::setDefault('x_name', 'x_other'); + + $actual = Tag::textField($options); + + Tag::resetInput(); + + $I->assertSame($expected, $actual); + + $expected = ''; + $actual = Tag::textField($options); + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: resetInput() - displayTo + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagResetInputDisplayTo(UnitTester $I) + { + $I->wantToTest('Tag - resetInput() - displayTo()'); + Tag::setDocType(Tag::XHTML10_STRICT); + $options = 'x_name'; + $expected = ''; + Tag::displayTo('x_name', 'x_other'); + $actual = Tag::textField($options); + Tag::resetInput(); + $I->assertSame($expected, $actual); + $expected = ''; + $actual = Tag::textField($options); + $I->assertSame($expected, $actual); + Tag::setDocType(Tag::HTML5); + $options = 'x_name'; + $expected = ''; + Tag::displayTo('x_name', 'x_other'); + $actual = Tag::textField($options); + Tag::resetInput(); + $I->assertSame($expected, $actual); + $expected = ''; + $actual = Tag::textField($options); + $I->assertSame($expected, $actual); + } +} diff --git a/tests/unit/Tag/SearchFieldCest.php b/tests/unit/Tag/SearchFieldCest.php new file mode 100644 index 00000000000..0dcd735434c --- /dev/null +++ b/tests/unit/Tag/SearchFieldCest.php @@ -0,0 +1,22 @@ + + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagHelper; + +class SearchFieldCest extends TagHelper +{ + protected $function = 'searchField'; + protected $inputType = 'search'; +} diff --git a/tests/unit/Tag/SetDefaultCest.php b/tests/unit/Tag/SetDefaultCest.php new file mode 100644 index 00000000000..35df41c3f6b --- /dev/null +++ b/tests/unit/Tag/SetDefaultCest.php @@ -0,0 +1,68 @@ + + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class SetDefaultCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: setDefault() + * + * @issue https://github.com/phalcon/cphalcon/issues/2402 + * @author Dmitry Patsura + * @since 2014-05-10 + */ + public function tagSetDefault(UnitTester $I) + { + $I->wantToTest('Tag - setDefault()'); + + Tag::setDefault('property1', 'testVal1'); + Tag::setDefault('property2', 'testVal2'); + Tag::setDefault('property3', 'testVal3'); + + $I->assertTrue( + Tag::hasValue('property1') + ); + + $I->assertTrue( + Tag::hasValue('property2') + ); + + $I->assertTrue( + Tag::hasValue('property3') + ); + + $I->assertFalse( + Tag::hasValue('property4') + ); + + $I->assertSame( + 'testVal1', + Tag::getValue('property1') + ); + + $I->assertSame( + 'testVal2', + Tag::getValue('property2') + ); + + $I->assertSame( + 'testVal3', + Tag::getValue('property3') + ); + } +} diff --git a/tests/unit/Tag/SetDefaultsCest.php b/tests/unit/Tag/SetDefaultsCest.php new file mode 100644 index 00000000000..af4dc122e32 --- /dev/null +++ b/tests/unit/Tag/SetDefaultsCest.php @@ -0,0 +1,71 @@ + + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class SetDefaultsCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: setDefaults() + * + * @author Phalcon Team + * @since 2018-11-13 + */ + public function tagSetDefaults(UnitTester $I) + { + $I->wantToTest('Tag - setDefaults()'); + + $data = [ + 'property1' => 'testVal1', + 'property2' => 'testVal2', + 'property3' => 'testVal3', + ]; + + Tag::setDefaults($data); + + $I->assertTrue( + Tag::hasValue('property1') + ); + + $I->assertTrue( + Tag::hasValue('property2') + ); + + $I->assertTrue( + Tag::hasValue('property3') + ); + + $I->assertFalse( + Tag::hasValue('property4') + ); + + $I->assertSame( + 'testVal1', + Tag::getValue('property1') + ); + + $I->assertSame( + 'testVal2', + Tag::getValue('property2') + ); + + $I->assertSame( + 'testVal3', + Tag::getValue('property3') + ); + } +} diff --git a/tests/unit/Tag/SetDocTypeCest.php b/tests/unit/Tag/SetDocTypeCest.php new file mode 100644 index 00000000000..18cdcb9e0a8 --- /dev/null +++ b/tests/unit/Tag/SetDocTypeCest.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 Phalcon\Tests\Unit\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class SetDocTypeCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: setDocType() + * + * @author Phalcon Team + * @since 2018-11-13 + */ + public function tagSetDocType(UnitTester $I) + { + $I->wantToTest('Tag - setDocType()'); + $this->runDoctypeTest($I, Tag::HTML32); + } +} diff --git a/tests/unit/Tag/SetTitleCest.php b/tests/unit/Tag/SetTitleCest.php new file mode 100644 index 00000000000..456fcaa6bc1 --- /dev/null +++ b/tests/unit/Tag/SetTitleCest.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\Tests\Unit\Tag; + +use Phalcon\Tag; +use UnitTester; + +class SetTitleCest +{ + /** + * Tests Phalcon\Tag :: setTitle() + * + * @author Phalcon Team + * @since 2018-11-13 + */ + public function tagSetTitle(UnitTester $I) + { + $I->wantToTest('Tag - setTitle()'); + + Tag::resetInput(); + + $value = 'This is my title'; + + Tag::setTitle($value); + + $I->assertSame( + "{$value}" . PHP_EOL, + Tag::renderTitle() + ); + + $I->assertSame( + "{$value}", + Tag::getTitle() + ); + } +} diff --git a/tests/unit/Tag/StylesheetLinkCest.php b/tests/unit/Tag/StylesheetLinkCest.php new file mode 100644 index 00000000000..6689615e28c --- /dev/null +++ b/tests/unit/Tag/StylesheetLinkCest.php @@ -0,0 +1,225 @@ + + * + * 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\Tag; + +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class StylesheetLinkCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: stylesheetLink() - string parameter for a local link + * + * @issue https://github.com/phalcon/cphalcon/issues/1486 + * @author Phalcon Team + * @author Dreamszhu + * @since 2014-09-12 + */ + public function tagStylesheetLinkStringParameterLocal(UnitTester $I) + { + $I->wantToTest('Tag - stylesheetLink() - string parameter for a local link'); + + Tag::resetInput(); + + $options = 'css/phalcon.css'; + $expected = '' . PHP_EOL; + + Tag::setDocType( + Tag::XHTML10_STRICT + ); + + $actual = Tag::stylesheetLink($options); + + $I->assertSame($expected, $actual); + + Tag::resetInput(); + + $options = 'css/phalcon.css'; + $expected = '' . PHP_EOL; + + Tag::setDocType( + Tag::HTML5 + ); + + $actual = Tag::stylesheetLink($options); + + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: stylesheetLink() - array parameter for a local link + * + * @issue https://github.com/phalcon/cphalcon/issues/1486 + * @author Phalcon Team + * @author Dreamszhu + * @since 2014-09-12 + */ + public function tagStylesheetLinkArrayParameterLocal(UnitTester $I) + { + $I->wantToTest('Tag - stylesheetLink() - array parameter for a local link'); + + Tag::resetInput(); + + $options = ['css/phalcon.css']; + $expected = '' + . PHP_EOL; + + Tag::setDocType( + Tag::XHTML10_STRICT + ); + + $actual = Tag::stylesheetLink($options); + + $I->assertSame($expected, $actual); + + Tag::resetInput(); + + $options = ['css/phalcon.css']; + $expected = '' + . PHP_EOL; + + Tag::setDocType( + Tag::HTML5 + ); + + $actual = Tag::stylesheetLink($options); + + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: stylesheetLink() - string parameter for a remote + * link + * + * @author Phalcon Team + * @since 2014-09-12 + */ + public function tagStylesheetLinkStringParameterRemote(UnitTester $I) + { + $I->wantToTest('Tag - stylesheetLink() - string parameter for a remote'); + + Tag::resetInput(); + + $options = 'http://phalcon.io/css/phalcon.css'; + $expected = '' . PHP_EOL; + + Tag::setDocType( + Tag::XHTML10_STRICT + ); + + $actual = Tag::stylesheetLink($options, false); + + $I->assertSame($expected, $actual); + + Tag::resetInput(); + + $options = 'http://phalcon.io/css/phalcon.css'; + $expected = '' . PHP_EOL; + + Tag::setDocType( + Tag::HTML5 + ); + + $actual = Tag::stylesheetLink($options, false); + + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: stylesheetLink() - array parameter for a remote link + * + * @author Phalcon Team + * @since 2014-09-12 + */ + public function tagStylesheetLinkArrayParameterRemote(UnitTester $I) + { + $I->wantToTest('Tag - stylesheetLink() - array parameter for a remote link'); + + Tag::resetInput(); + + $options = ['http://phalcon.io/css/phalcon.css']; + $expected = '' . PHP_EOL; + + Tag::setDocType( + Tag::XHTML10_STRICT + ); + + $actual = Tag::stylesheetLink($options, false); + + $I->assertSame($expected, $actual); + + Tag::resetInput(); + + $options = ['http://phalcon.io/css/phalcon.css']; + $expected = '' . PHP_EOL; + + Tag::setDocType( + Tag::HTML5 + ); + + $actual = Tag::stylesheetLink($options, false); + + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: stylesheetLink() - overriding the rel link local + * + * @issue https://github.com/phalcon/cphalcon/issues/2142 + * @author Phalcon Team + * @author Dreamszhu + * @since 2014-09-12 + */ + public function tagStylesheetLinkOverrideRelLink(UnitTester $I) + { + $I->wantToTest('Tag - stylesheetLink() - overriding the rel link local'); + + Tag::resetInput(); + + $options = [ + 'css/phalcon.css', + 'rel' => 'stylesheet/less', + ]; + + $expected = '' . PHP_EOL; + + Tag::setDocType( + Tag::XHTML10_STRICT + ); + + $actual = Tag::stylesheetLink($options); + + $I->assertSame($expected, $actual); + + Tag::resetInput(); + + $options = [ + 'css/phalcon.css', + 'rel' => 'stylesheet/less', + ]; + + $expected = '' . PHP_EOL; + + Tag::setDocType( + Tag::HTML5 + ); + + $actual = Tag::stylesheetLink($options); + + $I->assertSame($expected, $actual); + } +} diff --git a/tests/unit/Tag/SubmitButtonCest.php b/tests/unit/Tag/SubmitButtonCest.php new file mode 100644 index 00000000000..bba8ae5904e --- /dev/null +++ b/tests/unit/Tag/SubmitButtonCest.php @@ -0,0 +1,196 @@ + + * + * 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\Tag; + +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class SubmitButtonCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: submitButton() - string as a parameter + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagSubmitButtonStringParameter(UnitTester $I) + { + $I->wantToTest('Tag - submitButton() - string as parameter'); + + $options = 'x_name'; + $expected = 'testFieldParameter($I, 'submitButton', $options, $expected); + $this->testFieldParameter($I, 'submitButton', $options, $expected, true); + } + + /** + * Tests Phalcon\Tag :: submitButton() - array as a parameter + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagSubmitButtonArrayParameter(UnitTester $I) + { + $I->wantToTest('Tag - submitButton() - array as parameter'); + + $options = [ + 'x_name', + 'class' => 'x_class', + ]; + + $expected = 'testFieldParameter($I, 'submitButton', $options, $expected); + $this->testFieldParameter($I, 'submitButton', $options, $expected, true); + } + + /** + * Tests Phalcon\Tag :: submitButton() - array as parameter and id in it + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagSubmitButtonArrayParameterWithId(UnitTester $I) + { + $I->wantToTest('Tag - submitButton() - array as parameter with id'); + + $options = [ + 'x_name', + 'id' => 'x_id', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = 'testFieldParameter($I, 'submitButton', $options, $expected); + $this->testFieldParameter($I, 'submitButton', $options, $expected, true); + } + + /** + * Tests Phalcon\Tag :: submitButton() - name and no id in parameter + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagSubmitButtonArrayParameterWithNameNoId(UnitTester $I) + { + $I->wantToTest('Tag - submitButton() - name and no id in parameters'); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = 'testFieldParameter($I, 'submitButton', $options, $expected); + $this->testFieldParameter($I, 'submitButton', $options, $expected, true); + } + + /** + * Tests Phalcon\Tag :: submitButton() - setDefault + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagSubmitButtonWithSetDefault(UnitTester $I) + { + $I->wantToTest('Tag - submitButton() - setDefault()'); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = 'testFieldParameter($I, 'submitButton', $options, $expected, false, 'setDefault'); + $this->testFieldParameter($I, 'submitButton', $options, $expected, true, 'setDefault'); + } + + /** + * Tests Phalcon\Tag :: submitButton() - displayTo + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagSubmitButtonWithDisplayTo(UnitTester $I) + { + $I->wantToTest('Tag - submitButton() - displayTo()'); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = 'testFieldParameter($I, 'submitButton', $options, $expected, false, 'displayTo'); + $this->testFieldParameter($I, 'submitButton', $options, $expected, true, 'displayTo'); + } + + /** + * Tests Phalcon\Tag :: submitButton() - setDefault and element not present + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagSubmitButtonWithSetDefaultElementNotPresent(UnitTester $I) + { + $I->wantToTest('Tag - submitButton() - setDefault() and element not present'); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = 'testFieldParameter($I, 'submitButton', $options, $expected, false, 'setDefault'); + $this->testFieldParameter($I, 'submitButton', $options, $expected, true, 'setDefault'); + } + + /** + * Tests Phalcon\Tag :: submitButton() - displayTo and element not present + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagSubmitButtonWithDisplayToElementNotPresent(UnitTester $I) + { + $I->wantToTest('Tag - submitButton() - displayTo() and element not present'); + + $options = [ + 'x_name', + 'name' => 'x_other', + 'class' => 'x_class', + 'size' => '10', + ]; + + $expected = 'testFieldParameter($I, 'submitButton', $options, $expected, false, 'displayTo'); + $this->testFieldParameter($I, 'submitButton', $options, $expected, true, 'displayTo'); + } +} diff --git a/tests/unit/Tag/TagHtmlCest.php b/tests/unit/Tag/TagHtmlCest.php new file mode 100644 index 00000000000..3b86bac4da3 --- /dev/null +++ b/tests/unit/Tag/TagHtmlCest.php @@ -0,0 +1,209 @@ + + * + * 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\Tag; + +use Codeception\Example; +use Phalcon\Tag; +use Phalcon\Tests\Fixtures\Helpers\TagSetup; +use UnitTester; + +class TagHtmlCest extends TagSetup +{ + /** + * Tests Phalcon\Tag :: tagHtml() - name parameter + * + * @author Phalcon Team + * @since 2014-09-05 + * + * @dataProvider tagHtmlNameProvider + */ + public function tagTagHtmlName(UnitTester $I, Example $example) + { + $I->wantToTest('Tag - tagHtml() - name parameter'); + + Tag::resetInput(); + + $name = $example['name']; + + Tag::setDocType($example['docType']); + + $expected = $example['expected']; + $actual = Tag::tagHtml($name); + $I->assertSame($expected, $actual); + } + + /** + * Tests Phalcon\Tag :: tagHtml() - name parameter and self close + * + * @author Phalcon Team + * @since 2014-09-05 + */ + public function tagNameSelfClose(UnitTester $I) + { + $I->wantToTest('Tag - tagHtml() - name parameter self close'); + + Tag::resetInput(); + + $name = 'aside'; + $expected = '