From d2d94d177715dbd0b0d77ca6ed3506bb223e48ba Mon Sep 17 00:00:00 2001 From: Sid Roberts Date: Fri, 26 Apr 2019 07:31:37 +0900 Subject: [PATCH 1/4] Tidied up tests. --- tests/_ci/generate-test-stubs.php | 17 +- tests/_config/bootstrap.php | 25 +- .../fixtures/Acl/TestRoleComponentAware.php | 4 +- tests/_data/fixtures/Assets/CustomTag.php | 10 +- tests/_data/fixtures/Assets/TrimFilter.php | 11 +- tests/_data/fixtures/Db/Profiler.php | 1 - tests/_data/fixtures/Db/ProfilerListener.php | 2 - .../_data/fixtures/Di/InjectableComponent.php | 1 + tests/_data/fixtures/Di/SimpleComponent.php | 1 + tests/_data/fixtures/Di/SomeComponent.php | 1 + tests/_data/fixtures/Events/ComponentX.php | 16 +- .../Filter/{Sanitze => Sanitize}/IPv4.php | 6 +- tests/_data/fixtures/Helpers/TagHelper.php | 94 +- tests/_data/fixtures/Helpers/TagSetup.php | 84 +- .../fixtures/Helpers/TranslateQueryHelper.php | 86 +- tests/_data/fixtures/Http/PhpStream.php | 31 +- .../_data/fixtures/Listener/ThirdListener.php | 34 +- .../fixtures/Listener/ViewCompileListener.php | 15 +- tests/_data/fixtures/MemorySession.php | 11 +- tests/_data/fixtures/Micro/MyMiddleware.php | 9 +- .../_data/fixtures/Micro/MyMiddlewareStop.php | 10 +- tests/_data/fixtures/Micro/RestHandler.php | 25 +- .../fixtures/Mvc/View/Engine/Mustache.php | 6 +- tests/_data/fixtures/Mvc/View/Engine/Twig.php | 13 +- tests/_data/fixtures/Traits/AssetsTrait.php | 77 +- .../_data/fixtures/Traits/CollectionTrait.php | 38 +- tests/_data/fixtures/Traits/ConfigTrait.php | 212 ++- tests/_data/fixtures/Traits/CookieTrait.php | 19 +- tests/_data/fixtures/Traits/Db/MysqlTrait.php | 2 + .../fixtures/Traits/Db/PostgresqlTrait.php | 2 + tests/_data/fixtures/Traits/DiTrait.php | 87 +- tests/_data/fixtures/Traits/LoggerTrait.php | 4 - tests/_data/fixtures/Traits/RedisTrait.php | 1 + tests/_data/fixtures/Traits/RouterTrait.php | 23 +- .../_data/fixtures/Traits/TagHelperTrait.php | 69 +- tests/_data/fixtures/Traits/TagSetupTrait.php | 10 +- .../_data/fixtures/Traits/ValidationTrait.php | 64 +- tests/_data/fixtures/Traits/ViewTrait.php | 35 +- .../fixtures/controllers/MicroController.php | 2 + tests/_data/fixtures/models/Abonnes.php | 116 +- .../_data/fixtures/models/Cacheable/Model.php | 8 +- tests/_data/fixtures/models/Customers.php | 12 +- tests/_data/fixtures/models/Deles.php | 16 +- .../fixtures/models/Dynamic/Personers.php | 2 + .../_data/fixtures/models/Dynamic/Robots.php | 6 +- tests/_data/fixtures/models/GossipRobots.php | 6 +- tests/_data/fixtures/models/Language.php | 14 +- tests/_data/fixtures/models/LanguageI18n.php | 8 +- .../fixtures/models/ModelWithStringField.php | 12 +- .../fixtures/models/News/Subscribers.php | 28 +- tests/_data/fixtures/models/Packages.php | 4 +- tests/_data/fixtures/models/Parts.php | 17 +- tests/_data/fixtures/models/Parts2.php | 11 +- tests/_data/fixtures/models/Personers.php | 1 - tests/_data/fixtures/models/Pessoas.php | 1 - .../_data/fixtures/models/Relations/Deles.php | 16 +- .../fixtures/models/Relations/M2MRobots.php | 9 +- .../models/Relations/RelationsParts.php | 15 +- .../models/Relations/RelationsRobots.php | 12 +- .../models/Relations/RelationsRobotsParts.php | 27 +- .../fixtures/models/Relations/Robotters.php | 11 +- .../models/Relations/RobottersDeles.php | 26 +- .../fixtures/models/Relations/Some/Deles.php | 16 +- .../fixtures/models/Relations/Some/Parts.php | 16 +- .../fixtures/models/Relations/Some/Robots.php | 16 +- .../models/Relations/Some/RobotsParts.php | 27 +- .../models/Relations/Some/Robotters.php | 16 +- .../models/Relations/Some/RobottersDeles.php | 26 +- tests/_data/fixtures/models/RobotsParts.php | 29 +- tests/_data/fixtures/models/Robotters.php | 12 +- .../_data/fixtures/models/RobottersDeles.php | 26 +- .../_data/fixtures/models/Snapshot/Parts.php | 7 +- .../_data/fixtures/models/Snapshot/Robots.php | 7 +- .../fixtures/models/Snapshot/RobotsParts.php | 14 +- .../fixtures/models/Snapshot/Robotters.php | 7 +- .../fixtures/models/Snapshot/Subscribers.php | 28 +- tests/_data/fixtures/models/Some/Deles.php | 16 +- tests/_data/fixtures/models/Some/Parts.php | 16 +- tests/_data/fixtures/models/Some/Products.php | 1 - .../fixtures/models/Some/RobotsParts.php | 27 +- .../_data/fixtures/models/Some/Robotters.php | 16 +- .../fixtures/models/Some/RobottersDeles.php | 26 +- tests/_data/fixtures/models/Store/Parts.php | 11 +- tests/_data/fixtures/models/Store/Robots.php | 12 +- .../fixtures/models/Store/RobotsParts.php | 23 +- tests/_data/fixtures/models/Subscriptores.php | 77 +- .../fixtures/models/Validation/Robots.php | 1 + .../models/Validation/Subscriptores.php | 9 +- .../_data/fixtures/modules/backend/Module.php | 16 +- .../fixtures/modules/frontend/Module.php | 16 +- tests/_data/fixtures/resultsets/Stats.php | 4 +- tests/_data/fixtures/tasks/Issue787Task.php | 2 + tests/_support/AcceptanceTester.php | 3 +- tests/_support/CliTester.php | 3 +- tests/_support/FunctionalTester.php | 3 +- tests/_support/Helper/PhalconCacheFile.php | 87 +- tests/_support/Helper/PhalconLibmemcached.php | 39 +- tests/_support/Helper/Unit.php | 14 +- tests/_support/IntegrationTester.php | 8 +- tests/_support/UnitTester.php | 3 +- tests/cli/Cli/Console/ConstructCest.php | 15 +- tests/cli/Cli/Console/GetModuleCest.php | 15 +- tests/cli/Cli/Console/GetModulesCest.php | 9 +- tests/cli/Cli/Console/GetSetDICest.php | 9 +- .../Cli/Console/GetSetDefaultModuleCest.php | 6 +- .../Cli/Console/GetSetEventsManagerCest.php | 8 +- tests/cli/Cli/Console/HandleCest.php | 407 +++-- tests/cli/Cli/Console/RegisterModulesCest.php | 61 +- tests/cli/Cli/Console/SetArgumentCest.php | 51 +- tests/cli/Cli/Console/UnderscoreGetCest.php | 22 +- tests/cli/Cli/ConsoleCest.php | 776 +++++++--- tests/cli/Cli/DispatcherCest.php | 208 ++- .../Cli/Router/Route/GetDescriptionCest.php | 6 +- .../Cli/Router/Route/SetDescriptionCest.php | 6 +- tests/cli/Cli/RouterCest.php | 1309 ++++++++++------- tests/cli/Cli/TaskCest.php | 34 +- .../Db/Adapter/Pdo/Factory/LoadCest.php | 23 +- .../Adapter/Pdo/Mysql/DescribeColumnsCest.php | 16 +- .../Adapter/Pdo/Mysql/DescribeIndexesCest.php | 16 +- .../Pdo/Mysql/DescribeReferencesCest.php | 37 +- .../Db/Adapter/Pdo/Mysql/TableExistsCest.php | 24 +- .../Db/Adapter/Pdo/Mysql/TableOptionsCest.php | 8 +- .../integration/Db/Adapter/Pdo/MysqlCest.php | 178 ++- .../Pdo/Postgresql/DescribeColumnsCest.php | 12 +- .../Pdo/Postgresql/DescribeReferencesCest.php | 11 +- .../Pdo/Postgresql/TableExistsCest.php | 23 +- .../Db/Adapter/Pdo/PostgresqlCest.php | 182 ++- tests/integration/Db/Column/ConstantsCest.php | 1 + .../Db/Column/GetAfterPositionCest.php | 7 +- .../integration/Db/Column/GetBindTypeCest.php | 7 +- .../integration/Db/Column/GetDefaultCest.php | 7 +- tests/integration/Db/Column/GetNameCest.php | 7 +- tests/integration/Db/Column/GetScaleCest.php | 7 +- .../Db/Column/GetSchemaNameCest.php | 7 +- tests/integration/Db/Column/GetSizeCest.php | 7 +- tests/integration/Db/Column/GetTypeCest.php | 7 +- .../integration/Db/Column/HasDefaultCest.php | 14 +- .../Db/Column/IsAutoIncrementCest.php | 14 +- tests/integration/Db/Column/IsFirstCest.php | 7 +- tests/integration/Db/Column/IsNotNullCest.php | 7 +- tests/integration/Db/Column/IsNumericCest.php | 7 +- tests/integration/Db/Column/IsPrimaryCest.php | 7 +- .../integration/Db/Column/IsUnsignedCest.php | 7 +- tests/integration/Db/DbBindCest.php | 120 +- .../Db/Dialect/Helper/DialectBase.php | 210 ++- .../Db/Dialect/Helper/MysqlHelper.php | 181 ++- .../Db/Dialect/Helper/SqliteHelper.php | 31 +- .../integration/Db/Dialect/PostgresqlCest.php | 421 ++++-- tests/integration/Db/Dialect/SqliteCest.php | 472 ++++-- tests/integration/Db/IndexCest.php | 80 +- tests/integration/Forms/Element/TextCest.php | 217 ++- tests/integration/Forms/Form/AddCest.php | 2 + tests/integration/Forms/Form/ClearCest.php | 309 +++- tests/integration/Forms/Form/CountCest.php | 8 +- .../Forms/Form/GetMessagesCest.php | 16 +- .../Forms/Form/HasMessagesForCest.php | 24 +- tests/integration/Forms/Form/IsValidCest.php | 36 +- tests/integration/Forms/Form/RenderCest.php | 36 +- .../Forms/Form/SetValidationCest.php | 35 +- tests/integration/Forms/FormCest.php | 162 +- tests/integration/Forms/FormElementsCest.php | 114 +- tests/integration/Forms/FormsCest.php | 227 ++- .../Mvc/Dispatcher/Helper/BaseDispatcher.php | 21 +- .../Dispatcher/Helper/DispatcherListener.php | 4 +- ...TestAfterExecuteRouteForwardController.php | 15 +- ...estBeforeExecuteRouteForwardController.php | 15 +- .../DispatcherTestDefaultController.php | 31 +- ...atcherTestDefaultNoNamespaceController.php | 33 +- .../DispatcherTestDefaultTwoController.php | 31 +- ...patcherTestInitializeForwardController.php | 15 +- ...actor-DispatcherBeforeDispatchLoopCest.php | 107 +- ...actor-DispatcherBeforeExecuteRouteCest.php | 108 +- ...DispatcherBeforeExecuteRouteMethodCest.php | 85 +- ...efactor-DispatcherInitializeMethodCest.php | 31 +- .../Mvc/Dispatcher/Refactor-ForwardCest.php | 52 +- .../Mvc/Model/Refactor-CriteriaCest.php | 350 +++-- tests/integration/Mvc/Refactor-RouterCest.php | 261 ++-- tests/integration/Mvc/Refactor-UrlCest.php | 114 +- .../Mvc/Refactor-ViewEnginesCest.php | 52 +- .../Mvc/Router/RemoveExtraSlashesCest.php | 43 +- .../Engine/Volt/Compiler/AddFilterCest.php | 85 +- .../Engine/Volt/Compiler/AddFunctionCest.php | 95 +- .../Volt/Compiler/CompileStringCest.php | 50 +- .../View/Engine/Volt/Compiler/ParseCest.php | 81 +- .../Engine/Volt/Compiler/SetOptionCest.php | 27 +- .../Adapter/NativeArray/ConstructCest.php | 1 + .../Adapter/NativeArray/GetLimitCest.php | 8 +- .../Adapter/NativeArray/PaginateCest.php | 42 +- .../NativeArray/SetCurrentPageCest.php | 8 +- .../Adapter/NativeArray/SetLimitCest.php | 19 +- .../Paginator/Adapter/QueryBuilderCest.php | 19 +- .../Paginator/Adapter/RepositoryCest.php | 91 +- .../Paginator/Factory/LoadCest.php | 27 +- tests/integration/Refactor-PaginatorCest.php | 206 +-- tests/integration/Refactor-ValidationCest.php | 6 +- .../Session/Adapter/Files/CloseCest.php | 7 +- .../Session/Adapter/Files/ConstructCest.php | 8 +- .../Session/Adapter/Files/DestroyCest.php | 17 +- .../Session/Adapter/Files/GcCest.php | 29 +- .../Session/Adapter/Files/OpenCest.php | 8 +- .../Session/Adapter/Files/ReadCest.php | 8 +- .../Session/Adapter/Files/WriteCest.php | 17 +- .../Adapter/Libmemcached/CloseCest.php | 7 +- .../Adapter/Libmemcached/ConstructCest.php | 8 +- .../Adapter/Libmemcached/DestroyCest.php | 9 +- .../Session/Adapter/Libmemcached/GcCest.php | 25 +- .../Session/Adapter/Libmemcached/OpenCest.php | 7 +- .../Session/Adapter/Libmemcached/ReadCest.php | 8 +- .../Adapter/Libmemcached/WriteCest.php | 6 + .../Session/Adapter/Noop/CloseCest.php | 7 +- .../Session/Adapter/Noop/ConstructCest.php | 8 +- .../Session/Adapter/Noop/DestroyCest.php | 6 +- .../Session/Adapter/Noop/GcCest.php | 6 +- .../Session/Adapter/Noop/OpenCest.php | 10 +- .../Session/Adapter/Noop/ReadCest.php | 9 +- .../Session/Adapter/Noop/WriteCest.php | 7 +- .../Session/Adapter/Redis/CloseCest.php | 7 +- .../Session/Adapter/Redis/ConstructCest.php | 8 +- .../Session/Adapter/Redis/DestroyCest.php | 15 +- .../Session/Adapter/Redis/GcCest.php | 6 +- .../Session/Adapter/Redis/OpenCest.php | 7 +- .../Session/Adapter/Redis/ReadCest.php | 15 +- .../Session/Adapter/Redis/WriteCest.php | 10 +- tests/integration/Session/Bag/ClearCest.php | 20 +- .../integration/Session/Bag/ConstructCest.php | 7 +- tests/integration/Session/Bag/CountCest.php | 16 +- tests/integration/Session/Bag/GetCest.php | 36 +- .../Session/Bag/GetIteratorCest.php | 10 +- .../integration/Session/Bag/GetSetDICest.php | 11 +- tests/integration/Session/Bag/HasCest.php | 44 +- tests/integration/Session/Bag/InitCest.php | 16 +- .../Session/Bag/JsonSerializeCest.php | 12 +- tests/integration/Session/Bag/RemoveCest.php | 6 +- .../integration/Session/Bag/SerializeCest.php | 8 +- tests/integration/Session/Bag/SetCest.php | 25 +- tests/integration/Session/Bag/ToArrayCest.php | 8 +- tests/integration/Session/Bag/ToJsonCest.php | 11 +- .../Session/Bag/UnserializeCest.php | 9 +- .../integration/Session/Factory/LoadCest.php | 13 +- .../Session/Manager/ConstructCest.php | 8 +- .../Session/Manager/ExistsDestroyCest.php | 51 +- .../Session/Manager/GetSetCest.php | 26 +- .../Session/Manager/GetSetDICest.php | 8 +- .../Session/Manager/GetSetHandlerCest.php | 14 +- .../Session/Manager/GetSetIdCest.php | 34 +- .../Session/Manager/GetSetNameCest.php | 45 +- .../Session/Manager/GetSetOptionsCest.php | 18 +- tests/integration/Session/Manager/HasCest.php | 26 +- .../Session/Manager/RegenerateIdCest.php | 14 +- .../Session/Manager/RemoveCest.php | 29 +- .../Session/Manager/StatusCest.php | 31 +- .../Session/Manager/UnderscoreGetSetCest.php | 20 +- .../Session/Manager/UnderscoreIssetCest.php | 26 +- .../Session/Manager/UnderscoreUnsetCest.php | 32 +- tests/integration/Url/GetCest.php | 34 +- tests/integration/Url/GetSetDICest.php | 11 +- .../Url/GetSetStaticBaseUriCest.php | 13 +- .../CombinedFieldsValidator/ConstructCest.php | 1 + .../integration/Validation/ValidationCest.php | 184 ++- .../Validator/Alnum/ConstructCest.php | 2 + .../Validator/Alnum/GetOptionCest.php | 2 + .../Validator/Alnum/HasOptionCest.php | 8 +- .../Validator/Alnum/SetOptionCest.php | 2 + .../Validator/Alnum/ValidateCest.php | 103 +- .../Validator/Alpha/ConstructCest.php | 2 + .../Validator/Alpha/GetOptionCest.php | 2 + .../Validator/Alpha/HasOptionCest.php | 8 +- .../Validator/Alpha/SetOptionCest.php | 2 + .../Validator/Alpha/ValidateCest.php | 341 +++-- .../Validator/Between/ConstructCest.php | 2 + .../Validator/Between/GetOptionCest.php | 2 + .../Validator/Between/HasOptionCest.php | 8 +- .../Validator/Between/SetOptionCest.php | 2 + .../Validator/Between/ValidateCest.php | 147 +- .../Validator/Callback/ConstructCest.php | 2 + .../Validator/Callback/GetOptionCest.php | 2 + .../Validator/Callback/HasOptionCest.php | 8 +- .../Validator/Callback/SetOptionCest.php | 2 + .../Validator/Callback/ValidateCest.php | 238 ++- .../Validator/Confirmation/ConstructCest.php | 2 + .../Validator/Confirmation/GetOptionCest.php | 2 + .../Validator/Confirmation/HasOptionCest.php | 8 +- .../Validator/Confirmation/SetOptionCest.php | 2 + .../Validator/Confirmation/ValidateCest.php | 145 +- .../Validator/CreditCard/ConstructCest.php | 2 + .../Validator/CreditCard/GetOptionCest.php | 2 + .../Validator/CreditCard/HasOptionCest.php | 8 +- .../Validator/CreditCard/SetOptionCest.php | 2 + .../Validator/CreditCard/ValidateCest.php | 119 +- .../Validator/Date/ConstructCest.php | 2 + .../Validator/Date/GetOptionCest.php | 2 + .../Validator/Date/HasOptionCest.php | 8 +- .../Validator/Date/SetOptionCest.php | 2 + .../Validator/Date/ValidateCest.php | 1 + .../Validation/Validator/DateCest.php | 138 +- .../Validator/Digit/ConstructCest.php | 2 + .../Validator/Digit/GetOptionCest.php | 2 + .../Validator/Digit/HasOptionCest.php | 8 +- .../Validator/Digit/SetOptionCest.php | 2 + .../Validator/Digit/ValidateCest.php | 1 + .../Validation/Validator/DigitCest.php | 171 ++- .../Validator/Email/ConstructCest.php | 2 + .../Validator/Email/GetOptionCest.php | 2 + .../Validator/Email/HasOptionCest.php | 8 +- .../Validator/Email/SetOptionCest.php | 2 + .../Validator/Email/ValidateCest.php | 1 + .../Validator/ExclusionIn/ConstructCest.php | 2 + .../Validator/ExclusionIn/GetOptionCest.php | 2 + .../Validator/ExclusionIn/HasOptionCest.php | 8 +- .../Validator/ExclusionIn/SetOptionCest.php | 2 + .../Validator/ExclusionIn/ValidateCest.php | 1 + .../Validator/File/ConstructCest.php | 2 + .../Validator/File/GetOptionCest.php | 2 + .../Validator/File/HasOptionCest.php | 8 +- .../Validator/File/SetOptionCest.php | 2 + .../Validator/File/ValidateCest.php | 1 + .../Validator/Identical/ConstructCest.php | 2 + .../Validator/Identical/GetOptionCest.php | 2 + .../Validator/Identical/HasOptionCest.php | 8 +- .../Validator/Identical/SetOptionCest.php | 2 + .../Validator/Identical/ValidateCest.php | 1 + .../Validator/InclusionIn/ConstructCest.php | 2 + .../Validator/InclusionIn/GetOptionCest.php | 2 + .../Validator/InclusionIn/HasOptionCest.php | 8 +- .../Validator/InclusionIn/SetOptionCest.php | 2 + .../Validator/InclusionIn/ValidateCest.php | 1 + .../Validation/Validator/Ip/ConstructCest.php | 2 + .../Validation/Validator/Ip/GetOptionCest.php | 2 + .../Validation/Validator/Ip/HasOptionCest.php | 8 +- .../Validation/Validator/Ip/SetOptionCest.php | 2 + .../Validation/Validator/Ip/ValidateCest.php | 94 +- .../Validator/Numericality/ConstructCest.php | 2 + .../Validator/Numericality/GetOptionCest.php | 2 + .../Validator/Numericality/HasOptionCest.php | 8 +- .../Validator/Numericality/SetOptionCest.php | 2 + .../Validator/Numericality/ValidateCest.php | 1 + .../Validation/Validator/NumericalityCest.php | 114 +- .../Validator/PresenceOf/ConstructCest.php | 2 + .../Validator/PresenceOf/GetOptionCest.php | 2 + .../Validator/PresenceOf/HasOptionCest.php | 8 +- .../Validator/PresenceOf/SetOptionCest.php | 2 + .../Validator/PresenceOf/ValidateCest.php | 1 + .../Validator/Regex/ConstructCest.php | 2 + .../Validator/Regex/GetOptionCest.php | 2 + .../Validator/Regex/HasOptionCest.php | 8 +- .../Validator/Regex/SetOptionCest.php | 2 + .../Validator/Regex/ValidateCest.php | 1 + .../Validation/Validator/RegexCest.php | 162 +- .../Validator/StringLength/ConstructCest.php | 2 + .../Validator/StringLength/GetOptionCest.php | 2 + .../Validator/StringLength/HasOptionCest.php | 8 +- .../Validator/StringLength/SetOptionCest.php | 2 + .../Validator/StringLength/ValidateCest.php | 383 +++-- .../Validator/Uniqueness/ConstructCest.php | 2 + .../Validator/Uniqueness/GetOptionCest.php | 2 + .../Validator/Uniqueness/HasOptionCest.php | 8 +- .../Validator/Uniqueness/SetOptionCest.php | 2 + .../Validator/Uniqueness/ValidateCest.php | 1 + .../Validation/Validator/UniquenessCest.php | 393 +++-- .../Validator/Url/ConstructCest.php | 2 + .../Validator/Url/GetOptionCest.php | 2 + .../Validator/Url/HasOptionCest.php | 8 +- .../Validator/Url/SetOptionCest.php | 2 + .../Validation/Validator/Url/ValidateCest.php | 135 +- tests/shim.php | 12 +- tests/testbed/index.php | 7 +- .../Adapter/Memory/AddComponentAccessCest.php | 16 +- .../Acl/Adapter/Memory/AddComponentCest.php | 31 +- tests/unit/Acl/Adapter/Memory/AddRoleCest.php | 38 +- tests/unit/Acl/Adapter/Memory/AllowCest.php | 39 +- .../unit/Acl/Adapter/Memory/ConstructCest.php | 8 +- tests/unit/Acl/Adapter/Memory/DenyCest.php | 14 +- .../Adapter/Memory/GetActiveAccessCest.php | 22 +- .../Adapter/Memory/GetActiveComponentCest.php | 24 +- .../Adapter/Memory/GetActiveFunctionCest.php | 48 +- .../Acl/Adapter/Memory/GetActiveKeyCest.php | 24 +- .../Acl/Adapter/Memory/GetActiveRoleCest.php | 32 +- .../Acl/Adapter/Memory/GetComponentsCest.php | 4 + .../unit/Acl/Adapter/Memory/GetRolesCest.php | 2 + .../Memory/GetSetDefaultActionCest.php | 20 +- .../Memory/GetSetEventsManagerCest.php | 9 +- .../GetSetNoArgumentsDefaultActionCest.php | 28 +- .../unit/Acl/Adapter/Memory/IsAllowedCest.php | 34 +- .../Acl/Adapter/Memory/IsComponentCest.php | 18 +- tests/unit/Acl/Adapter/Memory/IsRoleCest.php | 16 +- tests/unit/Acl/Adapter/MemoryCest.php | 60 +- tests/unit/Assets/Asset/SetFilterCest.php | 2 +- tests/unit/Assets/Asset/SetLocalCest.php | 12 + tests/unit/Assets/Manager/OutputJsCest.php | 35 +- tests/unit/Assets/ManagerCest.php | 127 +- tests/unit/Collection/ClearCest.php | 19 +- tests/unit/Collection/GetCest.php | 35 +- tests/unit/Collection/GetIteratorCest.php | 9 +- tests/unit/Collection/HasCest.php | 44 +- tests/unit/Collection/InitCest.php | 16 +- tests/unit/Collection/JsonSerializeCest.php | 11 +- tests/unit/Collection/RemoveCest.php | 73 +- tests/unit/Collection/SerializeCest.php | 11 +- tests/unit/Collection/SetCest.php | 33 +- tests/unit/Collection/ToArrayCest.php | 11 +- tests/unit/Collection/ToJsonCest.php | 18 +- tests/unit/Collection/UnserializeCest.php | 13 +- tests/unit/Config/ConfigCest.php | 275 +++- tests/unit/Config/MergeCest.php | 14 +- tests/unit/Config/PathCest.php | 2 + tests/unit/Config/SetStateCest.php | 8 +- tests/unit/Config/ToArrayCest.php | 1 + tests/unit/Crypt/ConstructCest.php | 23 +- tests/unit/Crypt/DecryptCest.php | 3 + tests/unit/Crypt/EncryptCest.php | 32 +- tests/unit/Crypt/SetCipherCest.php | 9 +- tests/unit/Crypt/SetPaddingCest.php | 18 +- tests/unit/Events/ManagerCest.php | 138 +- tests/unit/Flash/Direct/Helper/FlashBase.php | 8 + tests/unit/Flash/SessionCest.php | 51 +- tests/unit/Helper/Str/RandomCest.php | 187 ++- tests/unit/Html/Breadcrumbs/AddCest.php | 16 +- tests/unit/Html/Breadcrumbs/ClearCest.php | 25 +- .../Html/Breadcrumbs/GetSetSeparatorCest.php | 9 +- tests/unit/Html/Breadcrumbs/RemoveCest.php | 31 +- tests/unit/Html/Breadcrumbs/RenderCest.php | 9 +- tests/unit/Html/Breadcrumbs/ToArrayCest.php | 9 +- tests/unit/Html/Helper/AnchorCest.php | 3 + tests/unit/Html/Helper/ButtonCest.php | 3 + tests/unit/Html/Helper/ElementCest.php | 2 + tests/unit/Html/Helper/FormCest.php | 3 + tests/unit/Html/Helper/FormCloseCest.php | 9 +- tests/unit/Html/Helper/TextAreaCest.php | 3 + tests/unit/Html/Tag/AppendTitleCest.php | 48 +- tests/unit/Html/Tag/ClearCest.php | 12 +- tests/unit/Html/Tag/ConstantsCest.php | 1 + tests/unit/Html/Tag/ElementCest.php | 38 +- tests/unit/Html/Tag/ElementCloseCest.php | 33 +- tests/unit/Html/Tag/EndFormCest.php | 16 +- tests/unit/Html/Tag/FriendlyTitleCest.php | 19 +- tests/unit/Http/Request/AuthHeaderCest.php | 67 +- tests/unit/Http/Request/RequestCest.php | 989 ++++++++++--- tests/unit/Http/Response/HeadersCest.php | 210 ++- tests/unit/Http/Response/ResponseCest.php | 18 +- tests/unit/Image/Adapter/Imagick/CropCest.php | 21 +- tests/unit/Image/Adapter/Imagick/FlipCest.php | 11 +- .../Adapter/Imagick/LiquidRescaleCest.php | 22 +- tests/unit/Image/Adapter/Imagick/MaskCest.php | 27 +- .../Image/Adapter/Imagick/ReflectionCest.php | 22 +- .../unit/Image/Adapter/Imagick/ResizeCest.php | 18 +- .../unit/Image/Adapter/Imagick/RotateCest.php | 22 +- tests/unit/Image/Adapter/Imagick/SaveCest.php | 15 +- .../Image/Adapter/Imagick/SharpenCest.php | 21 +- tests/unit/Image/Adapter/Imagick/TextCest.php | 22 +- .../Image/Adapter/Imagick/WatermarkCest.php | 27 +- tests/unit/Image/Factory/LoadCest.php | 42 +- tests/unit/Kernel/PreComputeHashKeyCest.php | 1 + tests/unit/Loader/LoaderCest.php | 232 ++- tests/unit/Logger/Adapter/Noop/AddCest.php | 22 +- tests/unit/Logger/Adapter/Noop/CommitCest.php | 31 +- .../Logger/Adapter/Noop/GetFormatterCest.php | 12 +- .../Logger/Adapter/Noop/InTransactionCest.php | 11 +- .../unit/Logger/Adapter/Noop/RollbackCest.php | 11 +- .../Logger/Adapter/Noop/SetFormatterCest.php | 12 +- tests/unit/Logger/Adapter/Stream/AddCest.php | 38 +- .../unit/Logger/Adapter/Stream/BeginCest.php | 18 +- .../unit/Logger/Adapter/Stream/CloseCest.php | 25 +- .../unit/Logger/Adapter/Stream/CommitCest.php | 47 +- .../Adapter/Stream/GetFormatterCest.php | 18 +- .../Logger/Adapter/Stream/GetNameCest.php | 20 +- .../Adapter/Stream/InTransactionCest.php | 19 +- .../Logger/Adapter/Stream/ProcessCest.php | 20 +- .../Logger/Adapter/Stream/RollbackCest.php | 23 +- .../Adapter/Stream/SetFormatterCest.php | 18 +- tests/unit/Logger/Adapter/Syslog/AddCest.php | 30 +- .../unit/Logger/Adapter/Syslog/CommitCest.php | 35 +- .../Adapter/Syslog/GetFormatterCest.php | 12 +- .../Adapter/Syslog/InTransactionCest.php | 14 +- .../Logger/Adapter/Syslog/ProcessCest.php | 16 +- .../Logger/Adapter/Syslog/RollbackCest.php | 14 +- .../Adapter/Syslog/SetFormatterCest.php | 12 +- tests/unit/Logger/AddAdapterCest.php | 37 +- tests/unit/Logger/AlertCest.php | 1 + tests/unit/Logger/ConstructCest.php | 36 +- tests/unit/Logger/CriticalCest.php | 1 + tests/unit/Logger/DebugCest.php | 1 + tests/unit/Logger/EmergencyCest.php | 1 + tests/unit/Logger/ErrorCest.php | 1 + tests/unit/Logger/ExcludeAdaptersCest.php | 15 +- tests/unit/Logger/Factory/LoadCest.php | 27 +- .../unit/Logger/Formatter/Json/FormatCest.php | 32 +- .../Formatter/Json/GetDateFormatCest.php | 8 +- .../Logger/Formatter/Json/InterpolateCest.php | 22 +- .../Formatter/Json/SetDateFormatCest.php | 9 +- .../unit/Logger/Formatter/Line/FormatCest.php | 18 +- .../Formatter/Line/GetDateFormatCest.php | 8 +- .../Logger/Formatter/Line/GetFormatCest.php | 8 +- .../Logger/Formatter/Line/InterpolateCest.php | 20 +- .../Formatter/Line/SetDateFormatCest.php | 9 +- .../Logger/Formatter/Line/SetFormatCest.php | 9 +- .../Logger/Formatter/Syslog/FormatCest.php | 19 +- .../Formatter/Syslog/InterpolateCest.php | 30 +- tests/unit/Logger/GetAdapterCest.php | 22 +- tests/unit/Logger/GetAdaptersCest.php | 41 +- tests/unit/Logger/GetNameCest.php | 8 +- tests/unit/Logger/InfoCest.php | 1 + tests/unit/Logger/Item/GetContextCest.php | 20 +- tests/unit/Logger/Item/GetMessageCest.php | 16 +- tests/unit/Logger/Item/GetNameCest.php | 16 +- tests/unit/Logger/Item/GetTimeCest.php | 16 +- tests/unit/Logger/Item/GetTypeCest.php | 16 +- tests/unit/Logger/LogCest.php | 22 +- tests/unit/Logger/NoticeCest.php | 1 + tests/unit/Logger/RemoveAdapterCest.php | 79 +- tests/unit/Logger/SetAdaptersCest.php | 89 +- tests/unit/Logger/WarningCest.php | 1 + tests/unit/Messages/Message/ConstructCest.php | 83 +- .../unit/Messages/Message/GetSetCodeCest.php | 8 +- .../unit/Messages/Message/GetSetFieldCest.php | 8 +- .../Messages/Message/GetSetMetaDataCest.php | 32 +- .../unit/Messages/Message/GetSetTypeCest.php | 8 +- .../Messages/Message/JsonSerializeCest.php | 30 +- tests/unit/Messages/Message/ToStringCest.php | 30 +- .../Messages/Messages/AppendMessageCest.php | 6 +- .../Messages/Messages/AppendMessagesCest.php | 40 +- .../unit/Messages/Messages/ConstructCest.php | 1 + tests/unit/Messages/Messages/CountCest.php | 8 +- tests/unit/Messages/Messages/CurrentCest.php | 35 +- tests/unit/Messages/Messages/FilterCest.php | 42 +- .../Messages/Messages/JsonSerializeCest.php | 33 +- tests/unit/Messages/Messages/KeyCest.php | 22 +- tests/unit/Messages/Messages/NextCest.php | 39 +- .../Messages/Messages/OffsetExistsCest.php | 30 +- .../Messages/Messages/OffsetGetSetCest.php | 48 +- .../Volt/Compiler/CompileStringCest.php | 49 +- tests/unit/Registry/ClearCest.php | 19 +- tests/unit/Registry/ConstructCest.php | 7 +- tests/unit/Registry/CountCest.php | 15 +- tests/unit/Security/Random/Base58Cest.php | 28 +- tests/unit/Security/Random/Base64Cest.php | 51 +- tests/unit/Security/Random/Base64SafeCest.php | 133 +- tests/unit/Service/Locator/ConstructCest.php | 2 + tests/unit/Service/Locator/GetSetHasCest.php | 54 +- .../Service/Locator/UnderscoreCallCest.php | 37 +- tests/unit/Session/ManagerCest.php | 9 +- tests/unit/Tag/AppendTitleCest.php | 120 +- tests/unit/Tag/FriendlyTitleCest.php | 48 +- tests/unit/Tag/GetTitleCest.php | 15 +- tests/unit/Tag/ImageCest.php | 38 +- tests/unit/Tag/ImageInputCest.php | 15 +- tests/unit/Tag/JavascriptIncludeCest.php | 71 +- tests/unit/Tag/LinkToCest.php | 111 +- tests/unit/Tag/PrependTitleCest.php | 129 +- tests/unit/Tag/RenderTitleCest.php | 11 +- tests/unit/Tag/ResetInputCest.php | 32 +- tests/unit/Tag/SelectCest.php | 11 +- tests/unit/Tag/SelectStaticCest.php | 158 +- tests/unit/Tag/SetDefaultCest.php | 37 +- tests/unit/Tag/SetDefaultsCest.php | 37 +- tests/unit/Tag/SetTitleCest.php | 17 +- tests/unit/Tag/StylesheetLinkCest.php | 103 +- tests/unit/Tag/SubmitButtonCest.php | 52 +- tests/unit/Tag/TagHtmlCest.php | 78 +- tests/unit/Tag/TagHtmlCloseCest.php | 26 +- tests/unit/Tag/TextAreaCest.php | 53 +- tests/unit/Text/CamelizeCest.php | 8 +- tests/unit/Text/ConcatCest.php | 5 +- tests/unit/Text/DynamicCest.php | 3 + tests/unit/Text/EndsWithCest.php | 32 +- tests/unit/Text/HumanizeCest.php | 29 +- tests/unit/Text/IncrementCest.php | 6 + tests/unit/Text/LowerCest.php | 64 +- tests/unit/Text/RandomCest.php | 190 ++- tests/unit/Text/ReduceSlashesCest.php | 29 +- tests/unit/Text/StartsWithCest.php | 60 +- tests/unit/Text/UncamelizeCest.php | 5 +- tests/unit/Text/UnderscoreCest.php | 29 +- tests/unit/Text/UpperCest.php | 65 +- .../Translate/Adapter/Csv/ConstructCest.php | 24 +- .../unit/Translate/Adapter/Csv/ExistsCest.php | 1 + tests/unit/Translate/Factory/LoadCest.php | 46 +- .../ReplacePlaceholdersCest.php | 11 +- .../IndexedArray/InterpolatorCest.php | 18 +- .../IndexedArray/ReplacePlaceholdersCest.php | 21 +- tests/unit/Version/ConstantsCest.php | 1 + tests/unit/Version/GetCest.php | 9 +- tests/unit/Version/GetIdCest.php | 36 +- tests/unit/Version/GetPartCest.php | 5 +- 583 files changed, 16205 insertions(+), 6297 deletions(-) rename tests/_data/fixtures/Filter/{Sanitze => Sanitize}/IPv4.php (84%) diff --git a/tests/_ci/generate-test-stubs.php b/tests/_ci/generate-test-stubs.php index e04a4c8a322..fb967ba6f68 100644 --- a/tests/_ci/generate-test-stubs.php +++ b/tests/_ci/generate-test-stubs.php @@ -52,6 +52,7 @@ public function %nn%%m%(UnitTester $I) $allClasses = get_declared_classes(); $phalconClasses = []; + foreach ($allClasses as $class) { if ('Phalcon\\' === substr($class, 0, 8)) { $phalconClasses[] = $class; @@ -68,9 +69,12 @@ public function %nn%%m%(UnitTester $I) ]; $outputFolder = dirname(dirname(__FILE__)) . '/nikos/'; + foreach ($phalconClasses as $class) { - $methods = get_class_methods($class); $newClass = str_replace('Phalcon\\', '', $class); + + $methods = get_class_methods($class); + sort($methods); foreach ($methods as $method) { @@ -109,14 +113,20 @@ public function %nn%%m%(UnitTester $I) break; } - $placeholders['%m%'] = ucfirst($method); + $placeholders['%m%'] = ucfirst($method); + + $dir = str_replace( + '\\', + '/', + $outputFolder . $class + ); - $dir = str_replace('\\', '/', $outputFolder . $class); @mkdir($dir, 0777, true); $from = array_keys($placeholders); $to = array_values($placeholders); $contents = str_replace($from, $to, $template); + $fileName = str_replace( '\\', '/', @@ -124,6 +134,7 @@ public function %nn%%m%(UnitTester $I) ); echo 'Filename: ' . $fileName . PHP_EOL; + file_put_contents($fileName, $contents); } } diff --git a/tests/_config/bootstrap.php b/tests/_config/bootstrap.php index 435d93401a4..4ea81956e0e 100644 --- a/tests/_config/bootstrap.php +++ b/tests/_config/bootstrap.php @@ -17,6 +17,7 @@ * Load environment */ $root = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR; + loadEnvironment($root); /** @@ -51,6 +52,7 @@ ]; $config = new Config($configFile); + $container->setShared('config', $config); /** @@ -60,7 +62,10 @@ 'view', function () use ($configFile) { $view = new View(); - $view->setViewsDir($configFile['application']['viewsDir']); + + $view->setViewsDir( + $configFile['application']['viewsDir'] + ); return $view; } @@ -87,11 +92,12 @@ function () use ($configFile) { ]; $loader->registerNamespaces($namespaces); + $loader->registerDirs( [ $configFile['application']['tasksDir'], $configFile['application']['controllersDir'], -// $configFile['application']['microDir'], + // $configFile['application']['microDir'], ] ); @@ -108,8 +114,13 @@ function () use ($configFile) { function () use ($configFile) { $url = new Url(); - $url->setStaticBaseUri($configFile['application']['staticUri']); - $url->setBaseUri($configFile['application']['baseUri']); + $url->setStaticBaseUri( + $configFile['application']['staticUri'] + ); + + $url->setBaseUri( + $configFile['application']['baseUri'] + ); return $url; } @@ -133,9 +144,13 @@ function () { /** * Session */ -$container->set(CodeceptionMemorySession::class, PhalconMemorySession::class); +$container->set( + CodeceptionMemorySession::class, + PhalconMemorySession::class +); $application = new Application(); + $application->setDI($container); FactoryDefault::setDefault($container); diff --git a/tests/_data/fixtures/Acl/TestRoleComponentAware.php b/tests/_data/fixtures/Acl/TestRoleComponentAware.php index 8c26c409c35..4b1ba0d2ba6 100644 --- a/tests/_data/fixtures/Acl/TestRoleComponentAware.php +++ b/tests/_data/fixtures/Acl/TestRoleComponentAware.php @@ -42,9 +42,9 @@ class TestRoleComponentAware implements RoleAware, ComponentAware */ public function __construct($user, $componentName, $roleName) { - $this->user = $user; + $this->user = $user; $this->componentName = $componentName; - $this->roleName = $roleName; + $this->roleName = $roleName; } /** diff --git a/tests/_data/fixtures/Assets/CustomTag.php b/tests/_data/fixtures/Assets/CustomTag.php index b30a962cadd..7bd6ee37337 100644 --- a/tests/_data/fixtures/Assets/CustomTag.php +++ b/tests/_data/fixtures/Assets/CustomTag.php @@ -15,11 +15,17 @@ class CustomTag extends \Phalcon\Tag { public static function stylesheetLink($parameters = null, bool $local = true): string { - return sprintf("\n", $parameters[0]); + return sprintf( + "\n", + $parameters[0] + ); } public static function javascriptInclude($parameters = null, bool $local = true): string { - return sprintf("\n", $parameters[0]); + return sprintf( + "\n", + $parameters[0] + ); } } diff --git a/tests/_data/fixtures/Assets/TrimFilter.php b/tests/_data/fixtures/Assets/TrimFilter.php index b7d42679061..e025dacc74b 100644 --- a/tests/_data/fixtures/Assets/TrimFilter.php +++ b/tests/_data/fixtures/Assets/TrimFilter.php @@ -27,6 +27,15 @@ class TrimFilter implements FilterInterface */ public function filter(string $content): string { - return str_replace(["\n", "\r", " ", "\t"], '', $content); + return str_replace( + [ + "\n", + "\r", + " ", + "\t", + ], + '', + $content + ); } } diff --git a/tests/_data/fixtures/Db/Profiler.php b/tests/_data/fixtures/Db/Profiler.php index 1ab37fed4c6..159286f3351 100644 --- a/tests/_data/fixtures/Db/Profiler.php +++ b/tests/_data/fixtures/Db/Profiler.php @@ -15,7 +15,6 @@ class Profiler extends PhalconProfiler { - private $points = 0; public function beforeStartProfile($profile) diff --git a/tests/_data/fixtures/Db/ProfilerListener.php b/tests/_data/fixtures/Db/ProfilerListener.php index 5e240f8ca95..9113677fc2b 100644 --- a/tests/_data/fixtures/Db/ProfilerListener.php +++ b/tests/_data/fixtures/Db/ProfilerListener.php @@ -13,7 +13,6 @@ class ProfilerListener { - protected $profiler; public function __construct() @@ -40,4 +39,3 @@ public function getProfiler() return $this->profiler; } } - diff --git a/tests/_data/fixtures/Di/InjectableComponent.php b/tests/_data/fixtures/Di/InjectableComponent.php index ac53ecad52c..d3ddc1ada00 100644 --- a/tests/_data/fixtures/Di/InjectableComponent.php +++ b/tests/_data/fixtures/Di/InjectableComponent.php @@ -1,4 +1,5 @@ eventsManager->fire('dummy:beforeAction', $this, 'extra data'); - $this->eventsManager->fire('dummy:afterAction', $this, ['extra', 'data']); + $this->eventsManager->fire( + 'dummy:beforeAction', + $this, + 'extra data' + ); + + $this->eventsManager->fire( + 'dummy:afterAction', + $this, + [ + 'extra', + 'data', + ] + ); } } diff --git a/tests/_data/fixtures/Filter/Sanitze/IPv4.php b/tests/_data/fixtures/Filter/Sanitize/IPv4.php similarity index 84% rename from tests/_data/fixtures/Filter/Sanitze/IPv4.php rename to tests/_data/fixtures/Filter/Sanitize/IPv4.php index c3daf19f3b1..e7b64b7b331 100644 --- a/tests/_data/fixtures/Filter/Sanitze/IPv4.php +++ b/tests/_data/fixtures/Filter/Sanitize/IPv4.php @@ -30,6 +30,10 @@ public function __invoke() $arguments = func_get_args(); $value = $arguments[0] ?? ''; - return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); + return filter_var( + $value, + FILTER_VALIDATE_IP, + FILTER_FLAG_IPV4 + ); } } diff --git a/tests/_data/fixtures/Helpers/TagHelper.php b/tests/_data/fixtures/Helpers/TagHelper.php index 0fec7df4383..e9ba5a50f50 100644 --- a/tests/_data/fixtures/Helpers/TagHelper.php +++ b/tests/_data/fixtures/Helpers/TagHelper.php @@ -27,7 +27,13 @@ class TagHelper extends TagSetup */ public function tagFieldStringParameter(UnitTester $I) { - $I->wantToTest(sprintf('Tag - %s() - string parameter', $this->function)); + $I->wantToTest( + sprintf( + 'Tag - %s() - string parameter', + $this->function + ) + ); + $options = 'x_name'; $expected = 'wantToTest(sprintf('Tag - %s() - array parameter', $this->function)); - $options = [ + $I->wantToTest( + sprintf( + 'Tag - %s() - array parameter', + $this->function + ) + ); + + $options = [ 'x_name', 'class' => 'x_class', ]; + $expected = 'testFieldParameter($I, $this->function, $options, $expected); @@ -62,13 +75,20 @@ public function tagFieldArrayParameter(UnitTester $I) */ public function tagFieldArrayParameterWithId(UnitTester $I) { - $I->wantToTest(sprintf('Tag - %s() - array parameter with id', $this->function)); - $options = [ + $I->wantToTest( + sprintf( + 'Tag - %s() - array parameter with id', + $this->function + ) + ); + + $options = [ 'x_name', 'id' => 'x_id', 'class' => 'x_class', 'size' => '10', ]; + $expected = 'wantToTest(sprintf('Tag - %s() - array parameter with name no id', $this->function)); - $options = [ + $I->wantToTest( + sprintf( + 'Tag - %s() - array parameter with name no id', + $this->function + ) + ); + + $options = [ 'x_name', 'name' => 'x_other', 'class' => 'x_class', 'size' => '10', ]; + $expected = 'testFieldParameter($I, $this->function, $options, $expected); @@ -105,13 +132,20 @@ public function tagFieldArrayParameterWithNameNoId(UnitTester $I) */ public function tagFieldWithSetDefault(UnitTester $I) { - $I->wantToTest(sprintf('Tag - %s() - setDefault()', $this->function)); - $options = [ + $I->wantToTest( + sprintf( + 'Tag - %s() - setDefault()', + $this->function + ) + ); + + $options = [ 'x_name', 'name' => 'x_other', 'class' => 'x_class', 'size' => '10', ]; + $expected = 'wantToTest(sprintf('Tag - %s() - string displayTo()', $this->function)); - $options = [ + $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'); @@ -150,16 +190,22 @@ public function tagFieldWithDisplayTo(UnitTester $I) */ public function tagFieldWithSetDefaultElementNotPresent(UnitTester $I) { - $I->wantToTest(sprintf('Tag - %s() - setDefault() element not present', $this->function)); - $options = [ + $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'); @@ -173,16 +219,22 @@ public function tagFieldWithSetDefaultElementNotPresent(UnitTester $I) */ public function tagFieldWithDisplayToElementNotPresent(UnitTester $I) { - $I->wantToTest(sprintf('Tag - %s() - displayTo() element not present', $this->function)); - $options = [ + $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/_data/fixtures/Helpers/TagSetup.php b/tests/_data/fixtures/Helpers/TagSetup.php index f8d09466ee1..3ade973848b 100644 --- a/tests/_data/fixtures/Helpers/TagSetup.php +++ b/tests/_data/fixtures/Helpers/TagSetup.php @@ -29,8 +29,12 @@ public function _before(UnitTester $I) $this->newDi(); $this->setDiEscaper(); $this->setDiUrl(); + Tag::resetInput(); - $this->doctype = $this->docTypeStringToConstant(Tag::getDocType()); + + $this->doctype = $this->docTypeStringToConstant( + Tag::getDocType() + ); } /** @@ -50,18 +54,21 @@ protected function docTypeStringToConstant(string $doctype) switch ($doctype) { case '' . PHP_EOL: return Tag::HTML32; + case '' . PHP_EOL: return Tag::HTML401_STRICT; + case '' . PHP_EOL: return Tag::HTML401_TRANSITIONAL; + case '' . PHP_EOL: return Tag::HTML401_FRAMESET; + case '' . PHP_EOL: return Tag::XHTML10_STRICT; + case '' . PHP_EOL: return Tag::XHTML10_TRANSITIONAL; + case '' . PHP_EOL: return Tag::XHTML10_FRAMESET; + case '' . PHP_EOL: return Tag::XHTML11; + case '' . PHP_EOL: return Tag::XHTML20; + default: return Tag::HTML5; } @@ -115,6 +128,7 @@ protected function docTypeStringToConstant(string $doctype) public function _after(UnitTester $I) { Tag::setDocType($this->doctype); + Tag::resetInput(); } @@ -127,6 +141,7 @@ public function _after(UnitTester $I) protected function runDoctypeTest(UnitTester $I, int $doctype) { Tag::resetInput(); + Tag::setDocType($doctype); $expected = $this->docTypeToString($doctype); @@ -150,62 +165,53 @@ protected function docTypeToString(int $doctype) switch ($doctype) { case 1: - return '' . PHP_EOL; + return '' . PHP_EOL; + case 2: - return '' . PHP_EOL; + case 3: return '' . PHP_EOL; + case 4: return '' . - PHP_EOL; + '"http://www.w3.org/TR/html4/frameset.dtd">' . PHP_EOL; + case 6: return '' . - PHP_EOL; + '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . PHP_EOL; + case 7: return '' . - PHP_EOL; + '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . PHP_EOL; + case 8: - return '' . - PHP_EOL; + '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">' . PHP_EOL; + case 9: return '' . - PHP_EOL; + '"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' . PHP_EOL; + case 10: - return '' . - PHP_EOL; + '"http://www.w3.org/MarkUp/DTD/xhtml2.dtd">' . PHP_EOL; + default: return '' . PHP_EOL; } @@ -224,10 +230,16 @@ protected function docTypeToString(int $doctype) protected function testFieldParameter(UnitTester $I, $function, $options, $expected, $xhtml = false, $set = '') { if ($xhtml) { - Tag::setDocType(Tag::XHTML10_STRICT); + Tag::setDocType( + Tag::XHTML10_STRICT + ); + $expected .= ' />'; } else { - Tag::setDocType(Tag::HTML5); + Tag::setDocType( + Tag::HTML5 + ); + $expected .= '>'; } diff --git a/tests/_data/fixtures/Helpers/TranslateQueryHelper.php b/tests/_data/fixtures/Helpers/TranslateQueryHelper.php index c5d8a73a93a..2e5b68574ba 100644 --- a/tests/_data/fixtures/Helpers/TranslateQueryHelper.php +++ b/tests/_data/fixtures/Helpers/TranslateQueryHelper.php @@ -42,11 +42,20 @@ public function translateAdapterNativearrayQuery(UnitTester $I, Example $data) $data['language'] ) ); - $language = $this->getArrayConfig()[$data['code']]; - $translator = new NativeArray(['content' => $language]); + + $language = $this->getArrayConfig()[$data['code']]; + + $translator = new NativeArray( + [ + 'content' => $language, + ] + ); + foreach ($data['tests'] as $key => $expected) { - $actual = $translator->{$this->function}($key); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $translator->{$this->function}($key) + ); } } @@ -70,11 +79,25 @@ public function translateAdapterNativearrayVariableSubstitutionNoVariables(UnitT $data['language'] ) ); - $language = $this->getArrayConfig()[$data['code']]; - $translator = new NativeArray(['content' => $language]); + + $language = $this->getArrayConfig()[$data['code']]; + + $translator = new NativeArray( + [ + 'content' => $language, + ] + ); + foreach ($data['tests'] as $key => $expected) { - $actual = $translator->{$this->function}($key, ['name' => 'my friend']); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $translator->{$this->function}( + $key, + [ + 'name' => 'my friend', + ] + ) + ); } } @@ -98,8 +121,15 @@ public function translateAdapterNativearrayVariableSubstitutionOneVariable(UnitT $data['language'] ) ); - $language = $this->getArrayConfig()[$data['code']]; - $translator = new NativeArray(['content' => $language]); + + $language = $this->getArrayConfig()[$data['code']]; + + $translator = new NativeArray( + [ + 'content' => $language, + ] + ); + foreach ($data['tests'] as $key => $expected) { $actual = $translator->{$this->function}($key, ['name' => 'my friend']); $I->assertEquals($expected, $actual); @@ -126,15 +156,25 @@ public function translateAdapterNativearrayVariableSubstitutionTwoVariable(UnitT $data['language'] ) ); - $language = $this->getArrayConfig()[$data['code']]; - $translator = new NativeArray(['content' => $language]); - $vars = [ + + $language = $this->getArrayConfig()[$data['code']]; + + $translator = new NativeArray( + [ + 'content' => $language, + ] + ); + + $vars = [ 'song' => 'Dust in the wind', 'artist' => 'Kansas', ]; + foreach ($data['tests'] as $key => $expected) { - $actual = $translator->{$this->function}($key, $vars); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $translator->{$this->function}($key, $vars) + ); } } @@ -148,8 +188,13 @@ public function translateAdapterNativearrayVariableSubstitutionTwoVariable(UnitT */ public function testWithArrayAccessAndUTF8Strings(UnitTester $I) { - $language = $this->getArrayConfig()['ru']; - $translator = new NativeArray(['content' => $language]); + $language = $this->getArrayConfig()['ru']; + + $translator = new NativeArray( + [ + 'content' => $language, + ] + ); $vars = [ 'fname' => 'John', @@ -157,9 +202,10 @@ public function testWithArrayAccessAndUTF8Strings(UnitTester $I) 'mname' => 'D.', ]; - $expected = 'Привет, John D. Doe!'; - $actual = $translator->{$this->function}('Hello %fname% %mname% %lname%!', $vars); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'Привет, John D. Doe!', + $translator->{$this->function}('Hello %fname% %mname% %lname%!', $vars) + ); } /** diff --git a/tests/_data/fixtures/Http/PhpStream.php b/tests/_data/fixtures/Http/PhpStream.php index 4735d242f24..7e41b09cbe2 100644 --- a/tests/_data/fixtures/Http/PhpStream.php +++ b/tests/_data/fixtures/Http/PhpStream.php @@ -15,8 +15,8 @@ /** * Helper\Http\PhpStream * - * @link http://php.net/manual/en/class.streamwrapper.php - * @link http://php.net/manual/en/stream.streamwrapper.example-1.php + * @link http://php.net/manual/en/class.streamwrapper.php + * @link http://php.net/manual/en/stream.streamwrapper.example-1.php * * @codingStandardsIgnoreFile * @package Helper @@ -30,7 +30,9 @@ class PhpStream public function __construct() { if (file_exists($this->getBufferFilename())) { - $this->data = file_get_contents($this->getBufferFilename()); + $this->data = file_get_contents( + $this->getBufferFilename() + ); } $this->index = 0; @@ -67,7 +69,11 @@ public function stream_read($count) $this->length = strlen($this->data); } - $length = min($count, $this->length - $this->index); + $length = min( + $count, + $this->length - $this->index + ); + $data = substr($this->data, $this->index); $this->index = $this->index + $length; @@ -76,7 +82,7 @@ public function stream_read($count) public function stream_eof() { - return ($this->index >= $this->length ? true : false); + return ($this->index >= $this->length); } public function stream_seek($offset, $whence) @@ -89,24 +95,30 @@ public function stream_seek($offset, $whence) case SEEK_SET: if ($offset < $this->length && $offset >= 0) { $this->index = $offset; + return true; } else { return false; } + case SEEK_CUR: if ($offset >= 0) { $this->index += $offset; + return true; } else { return false; } + case SEEK_END: if ($this->length + $offset >= 0) { $this->index = $this->length + $offset; + return true; } else { return false; } + default: return false; } @@ -114,13 +126,18 @@ public function stream_seek($offset, $whence) public function stream_write($data) { - return file_put_contents($this->getBufferFilename(), $data); + return file_put_contents( + $this->getBufferFilename(), + $data + ); } public function unlink() { if (file_exists($this->getBufferFilename())) { - unlink($this->getBufferFilename()); + unlink( + $this->getBufferFilename() + ); } $this->data = ''; diff --git a/tests/_data/fixtures/Listener/ThirdListener.php b/tests/_data/fixtures/Listener/ThirdListener.php index 17f12172a40..618cbce77dd 100644 --- a/tests/_data/fixtures/Listener/ThirdListener.php +++ b/tests/_data/fixtures/Listener/ThirdListener.php @@ -43,18 +43,40 @@ public function setTestCase(ManagerCest $testCase, UnitTester $tester) public function beforeAction($event, $component, $data) { - $this->tester->assertInstanceOf(Event::class, $event); - $this->tester->assertInstanceOf(ComponentX::class, $component); - $this->tester->assertEquals($data, 'extra data'); + $this->tester->assertInstanceOf( + Event::class, + $event + ); + + $this->tester->assertInstanceOf( + ComponentX::class, + $component + ); + + $this->tester->assertEquals( + 'extra data', + $data + ); $this->before++; } public function afterAction($event, $component) { - $this->tester->assertInstanceOf(Event::class, $event); - $this->tester->assertInstanceOf(ComponentX::class, $component); - $this->tester->assertEquals($event->getData(), ['extra', 'data']); + $this->tester->assertInstanceOf( + Event::class, + $event + ); + + $this->tester->assertInstanceOf( + ComponentX::class, + $component + ); + + $this->tester->assertEquals( + ['extra', 'data'], + $event->getData() + ); $this->after++; diff --git a/tests/_data/fixtures/Listener/ViewCompileListener.php b/tests/_data/fixtures/Listener/ViewCompileListener.php index 12273a9a51d..9907c0aa3d1 100644 --- a/tests/_data/fixtures/Listener/ViewCompileListener.php +++ b/tests/_data/fixtures/Listener/ViewCompileListener.php @@ -13,6 +13,7 @@ namespace Phalcon\Test\Fixtures\Listener; use ComponentX; +use IntegrationTester; use Phalcon\Events\Event; use Phalcon\Test\Integration\Mvc\View\Engine\Volt\RenderCest; use UnitTester; @@ -31,7 +32,7 @@ class ViewCompileListener protected $before = ''; protected $after = ''; - public function setTestCase(RenderCest $testCase, \IntegrationTester $tester) + public function setTestCase(RenderCest $testCase, IntegrationTester $tester) { $this->testCase = $testCase; $this->tester = $tester; @@ -43,7 +44,11 @@ public function setTestCase(RenderCest $testCase, \IntegrationTester $tester) */ public function beforeCompile($event, $component) { - $this->tester->assertInstanceOf(Event::class, $event); + $this->tester->assertInstanceOf( + Event::class, + $event + ); + $this->before = "Before fired"; } @@ -53,7 +58,11 @@ public function beforeCompile($event, $component) */ public function afterCompile($event, $component) { - $this->tester->assertInstanceOf(Event::class, $event); + $this->tester->assertInstanceOf( + Event::class, + $event + ); + $this->after = "After fired"; } diff --git a/tests/_data/fixtures/MemorySession.php b/tests/_data/fixtures/MemorySession.php index e972367bc00..018be5b5294 100644 --- a/tests/_data/fixtures/MemorySession.php +++ b/tests/_data/fixtures/MemorySession.php @@ -190,7 +190,9 @@ public function getOptions(): array */ public function has(string $index): bool { - return isset($this->memory[$this->prepareIndex($index)]); + return isset( + $this->memory[$this->prepareIndex($index)] + ); } /** @@ -213,7 +215,9 @@ public function regenerateId($deleteOldSession = true): ManagerInterface */ public function remove(string $index) { - unset($this->memory[$this->prepareIndex($index)]); + unset( + $this->memory[$this->prepareIndex($index)] + ); } /** @@ -368,4 +372,5 @@ public function setHandler(\SessionHandlerInterface $handler): ManagerInterface public function registerHandler(\SessionHandlerInterface $handler): bool { // TODO: Implement registerHandler() method. -}} + } +} diff --git a/tests/_data/fixtures/Micro/MyMiddleware.php b/tests/_data/fixtures/Micro/MyMiddleware.php index 782f860fcde..f8537e0887b 100644 --- a/tests/_data/fixtures/Micro/MyMiddleware.php +++ b/tests/_data/fixtures/Micro/MyMiddleware.php @@ -11,19 +11,20 @@ namespace Phalcon\Test\Fixtures\Micro; +use Phalcon\Mvc\Micro; use Phalcon\Mvc\Micro\MiddlewareInterface; class MyMiddleware implements MiddlewareInterface { - protected $_number = 0; + protected $number = 0; - public function call(\Phalcon\Mvc\Micro $application) + public function call(Micro $application) { - $this->_number++; + $this->number++; } public function getNumber() { - return $this->_number; + return $this->number; } } diff --git a/tests/_data/fixtures/Micro/MyMiddlewareStop.php b/tests/_data/fixtures/Micro/MyMiddlewareStop.php index 81f5e42e2e8..0a111e601fb 100644 --- a/tests/_data/fixtures/Micro/MyMiddlewareStop.php +++ b/tests/_data/fixtures/Micro/MyMiddlewareStop.php @@ -11,20 +11,22 @@ namespace Phalcon\Test\Fixtures\Micro; +use Phalcon\Mvc\Micro; use Phalcon\Mvc\Micro\MiddlewareInterface; class MyMiddlewareStop implements MiddlewareInterface { - protected $_number = 0; + protected $number = 0; - public function call(\Phalcon\Mvc\Micro $application) + public function call(Micro $application) { $application->stop(); - $this->_number++; + + $this->number++; } public function getNumber() { - return $this->_number; + return $this->number; } } diff --git a/tests/_data/fixtures/Micro/RestHandler.php b/tests/_data/fixtures/Micro/RestHandler.php index 300cb5d2091..c97e4c315ae 100644 --- a/tests/_data/fixtures/Micro/RestHandler.php +++ b/tests/_data/fixtures/Micro/RestHandler.php @@ -13,37 +13,42 @@ class RestHandler { - protected $_access = 0; + protected $access = 0; - protected $_trace = []; + protected $trace = []; public function find() { - $this->_access++; - $this->_trace[] = "find"; + $this->access++; + + $this->trace[] = "find"; } public function save() { - $this->_access++; - $this->_trace[] = "save"; + $this->access++; + + $this->trace[] = "save"; } public function delete() { - $this->_access++; - $this->_trace[] = "delete"; + $this->access++; + + $this->trace[] = "delete"; } + + public function getNumberAccess() { - return $this->_access; + return $this->access; } public function getTrace() { - return $this->_trace; + return $this->trace; } } diff --git a/tests/_data/fixtures/Mvc/View/Engine/Mustache.php b/tests/_data/fixtures/Mvc/View/Engine/Mustache.php index 97e4d6e389d..c57ef148bf1 100644 --- a/tests/_data/fixtures/Mvc/View/Engine/Mustache.php +++ b/tests/_data/fixtures/Mvc/View/Engine/Mustache.php @@ -57,7 +57,11 @@ public function render($path, $params, $mustClean = false) $params['content'] = $this->view->getContent(); } - $content = $this->mustache->render(file_get_contents($path), $params); + $content = $this->mustache->render( + file_get_contents($path), + $params + ); + if ($mustClean) { $this->view->setContent($content); } else { diff --git a/tests/_data/fixtures/Mvc/View/Engine/Twig.php b/tests/_data/fixtures/Mvc/View/Engine/Twig.php index cd989bbe96d..7ceeee36571 100644 --- a/tests/_data/fixtures/Mvc/View/Engine/Twig.php +++ b/tests/_data/fixtures/Mvc/View/Engine/Twig.php @@ -30,7 +30,11 @@ class Twig extends Engine implements EngineInterface */ public function __construct(ViewBaseInterface $view, DiInterface $dependencyInjector = null) { - $this->twig = new Twig_Environment(new Twig_Loader_Filesystem($view->getViewsDir())); + $this->twig = new Twig_Environment( + new Twig_Loader_Filesystem( + $view->getViewsDir() + ) + ); parent::__construct($view, $dependencyInjector); } @@ -52,7 +56,12 @@ public function render($path, $params, $mustClean = false) $params['view'] = $this->view; } - $relativePath = str_replace($this->view->getViewsDir(), '', $path); + $relativePath = str_replace( + $this->view->getViewsDir(), + '', + $path + ); + $content = $this->twig->render($relativePath, $params); if ($mustClean) { diff --git a/tests/_data/fixtures/Traits/AssetsTrait.php b/tests/_data/fixtures/Traits/AssetsTrait.php index e48a67fe334..c15cc4e49e7 100644 --- a/tests/_data/fixtures/Traits/AssetsTrait.php +++ b/tests/_data/fixtures/Traits/AssetsTrait.php @@ -29,8 +29,10 @@ trait AssetsTrait */ private function assetGetAssetKey(UnitTester $I, AssetInterface $asset, string $expected) { - $actual = $asset->getAssetKey(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $asset->getAssetKey() + ); } /** @@ -40,8 +42,10 @@ private function assetGetAssetKey(UnitTester $I, AssetInterface $asset, string $ */ private function assetGetAttributes(UnitTester $I, AssetInterface $asset, array $expected) { - $actual = $asset->getAttributes(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $asset->getAttributes() + ); } /** @@ -51,8 +55,10 @@ private function assetGetAttributes(UnitTester $I, AssetInterface $asset, array */ private function assetGetContent(UnitTester $I, AssetInterface $asset, string $expected) { - $actual = $asset->getContent(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $asset->getContent() + ); } /** @@ -62,8 +68,10 @@ private function assetGetContent(UnitTester $I, AssetInterface $asset, string $e */ private function assetGetFilter(UnitTester $I, AssetInterface $asset, bool $expected) { - $actual = $asset->getFilter(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $asset->getFilter() + ); } /** @@ -72,8 +80,9 @@ private function assetGetFilter(UnitTester $I, AssetInterface $asset, bool $expe */ private function assetGetLocal(UnitTester $I, AssetInterface $asset) { - $actual = $asset->getLocal(); - $I->assertTrue($actual); + $I->assertTrue( + $asset->getLocal() + ); } /** @@ -83,8 +92,10 @@ private function assetGetLocal(UnitTester $I, AssetInterface $asset) */ private function assetGetPath(UnitTester $I, AssetInterface $asset, string $expected) { - $actual = $asset->getPath(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $asset->getPath() + ); } /** @@ -94,8 +105,10 @@ private function assetGetPath(UnitTester $I, AssetInterface $asset, string $expe */ private function assetGetRealSourcePath(UnitTester $I, AssetInterface $asset, $expected) { - $actual = $asset->getRealSourcePath(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $asset->getRealSourcePath() + ); } /** @@ -105,8 +118,10 @@ private function assetGetRealSourcePath(UnitTester $I, AssetInterface $asset, $e */ private function assetGetRealTargetPath(UnitTester $I, AssetInterface $asset, string $expected) { - $actual = $asset->getRealTargetPath(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $asset->getRealTargetPath() + ); } /** @@ -116,8 +131,10 @@ private function assetGetRealTargetPath(UnitTester $I, AssetInterface $asset, st */ private function assetGetRealTargetUri(UnitTester $I, AssetInterface $asset, $expected) { - $actual = $asset->getRealTargetUri(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $asset->getRealTargetUri() + ); } /** @@ -127,8 +144,10 @@ private function assetGetRealTargetUri(UnitTester $I, AssetInterface $asset, $ex */ private function assetGetSourcePath(UnitTester $I, AssetInterface $asset, string $expected) { - $actual = $asset->getSourcePath(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $asset->getSourcePath() + ); } /** @@ -138,8 +157,10 @@ private function assetGetSourcePath(UnitTester $I, AssetInterface $asset, string */ private function assetGetTargetPath(UnitTester $I, AssetInterface $asset, string $expected) { - $actual = $asset->getTargetPath(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $asset->getTargetPath() + ); } /** @@ -149,8 +170,10 @@ private function assetGetTargetPath(UnitTester $I, AssetInterface $asset, string */ private function assetGetTargetUri(UnitTester $I, AssetInterface $asset, string $expected) { - $actual = $asset->getTargetUri(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $asset->getTargetUri() + ); } /** @@ -160,7 +183,9 @@ private function assetGetTargetUri(UnitTester $I, AssetInterface $asset, string */ private function assetGetType(UnitTester $I, AssetInterface $asset, string $expected) { - $actual = $asset->getType(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $asset->getType() + ); } } diff --git a/tests/_data/fixtures/Traits/CollectionTrait.php b/tests/_data/fixtures/Traits/CollectionTrait.php index f6ed5315d81..227e06ca47c 100644 --- a/tests/_data/fixtures/Traits/CollectionTrait.php +++ b/tests/_data/fixtures/Traits/CollectionTrait.php @@ -27,8 +27,6 @@ trait CollectionTrait { /** * Executed before each test - * - * @param Actor $I */ protected function setupMongo(Actor $I) { @@ -38,20 +36,32 @@ protected function setupMongo(Actor $I) ); } - $I->haveServiceInDi('mongo', function () { - $dsn = sprintf('mongodb://%s:%s', DATA_MONGODB_HOST, DATA_MONGODB_PORT); + $I->haveServiceInDi( + 'mongo', + function () { + $dsn = sprintf( + 'mongodb://%s:%s', + DATA_MONGODB_HOST, + DATA_MONGODB_PORT + ); - if (class_exists('MongoClient')) { - $mongo = new MongoClient($dsn); - } else { - $mongo = new Mongo($dsn); - } + if (class_exists('MongoClient')) { + $mongo = new MongoClient($dsn); + } else { + $mongo = new Mongo($dsn); + } - return $mongo->selectDB(DATA_MONGODB_NAME); - }, true); + return $mongo->selectDB(DATA_MONGODB_NAME); + }, + true + ); - $I->haveServiceInDi('collectionManager', function () { - return new Manager(); - }, true); + $I->haveServiceInDi( + 'collectionManager', + function () { + return new Manager(); + }, + true + ); } } diff --git a/tests/_data/fixtures/Traits/ConfigTrait.php b/tests/_data/fixtures/Traits/ConfigTrait.php index 9f2db278b43..1568eb69c28 100644 --- a/tests/_data/fixtures/Traits/ConfigTrait.php +++ b/tests/_data/fixtures/Traits/ConfigTrait.php @@ -80,8 +80,15 @@ trait ConfigTrait */ private function checkConstruct(UnitTester $I, string $adapter = '') { - $I->wantToTest(sprintf($this->getMessage($adapter), 'construct')); + $I->wantToTest( + sprintf( + $this->getMessage($adapter), + 'construct' + ) + ); + $config = $this->getConfig($adapter); + $this->compareConfig($I, $this->config, $config); } @@ -136,10 +143,15 @@ private function getConfig(string $adapter = '') */ private function compareConfig(UnitTester $I, array $actual, Config $expected) { - $I->assertEquals($actual, $expected->toArray()); + $I->assertEquals( + $expected->toArray(), + $actual + ); foreach ($actual as $key => $value) { - $I->assertTrue(isset($expected->$key)); + $I->assertTrue( + isset($expected->$key) + ); if (is_array($value)) { $this->compareConfig($I, $value, $expected->$key); @@ -160,12 +172,19 @@ private function compareConfig(UnitTester $I, array $actual, Config $expected) */ private function checkCount(UnitTester $I, string $adapter = '') { - $I->wantToTest(sprintf($this->getMessage($adapter), 'count()')); + $I->wantToTest( + sprintf( + $this->getMessage($adapter), + 'count()' + ) + ); + $config = $this->getConfig($adapter); - $expected = 5; - $actual = $config->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 5, + $config->count() + ); } /** @@ -179,12 +198,19 @@ private function checkCount(UnitTester $I, string $adapter = '') */ private function checkGet(UnitTester $I, string $adapter = '') { - $I->wantToTest(sprintf($this->getMessage($adapter), 'get()')); + $I->wantToTest( + sprintf( + $this->getMessage($adapter), + 'get()' + ) + ); + $config = $this->getConfig($adapter); - $expected = 'memory'; - $actual = $config->get('models')->get('metadata'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'memory', + $config->get('models')->get('metadata') + ); } /** @@ -198,20 +224,34 @@ private function checkGet(UnitTester $I, string $adapter = '') */ private function checkGetPathDelimiter(UnitTester $I, string $adapter = '') { - $I->wantToTest(sprintf($this->getMessage($adapter), 'getPathDelimiter()')); + $I->wantToTest( + sprintf( + $this->getMessage($adapter), + 'getPathDelimiter()' + ) + ); + $config = $this->getConfig($adapter); $existing = $config->getPathDelimiter(); - $expected = '.'; - $actual = $config->getPathDelimiter(); - $I->assertEquals($expected, $actual); + + + $I->assertEquals( + '.', + $config->getPathDelimiter() + ); + + $config->setPathDelimiter('/'); - $expected = '/'; - $actual = $config->getPathDelimiter(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + '/', + $config->getPathDelimiter() + ); + + $config->setPathDelimiter($existing); } @@ -227,11 +267,18 @@ private function checkGetPathDelimiter(UnitTester $I, string $adapter = '') */ private function checkOffsetExists(UnitTester $I, string $adapter = '') { - $I->wantToTest(sprintf($this->getMessage($adapter), 'offsetExists()')); + $I->wantToTest( + sprintf( + $this->getMessage($adapter), + 'offsetExists()' + ) + ); + $config = $this->getConfig($adapter); - $actual = $config->offsetExists('models'); - $I->assertTrue($actual); + $I->assertTrue( + $config->offsetExists('models') + ); } /** @@ -245,12 +292,19 @@ private function checkOffsetExists(UnitTester $I, string $adapter = '') */ private function checkOffsetGet(UnitTester $I, string $adapter = '') { - $I->wantToTest(sprintf($this->getMessage($adapter), 'offsetGet()')); + $I->wantToTest( + sprintf( + $this->getMessage($adapter), + 'offsetGet()' + ) + ); + $config = $this->getConfig($adapter); - $expected = 'memory'; - $actual = $config->offsetGet('models')->offsetGet('metadata'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'memory', + $config->offsetGet('models')->offsetGet('metadata') + ); } /** @@ -264,14 +318,21 @@ private function checkOffsetGet(UnitTester $I, string $adapter = '') */ private function checkOffsetSet(UnitTester $I, string $adapter = '') { - $I->wantToTest(sprintf($this->getMessage($adapter), 'offsetSet()')); + $I->wantToTest( + sprintf( + $this->getMessage($adapter), + 'offsetSet()' + ) + ); + $config = $this->getConfig($adapter); $config->offsetSet('models', 'something-else'); - $expected = 'something-else'; - $actual = $config->offsetGet('models'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'something-else', + $config->offsetGet('models') + ); } /** @@ -285,15 +346,24 @@ private function checkOffsetSet(UnitTester $I, string $adapter = '') */ private function checkOffsetUnset(UnitTester $I, string $adapter = '') { - $I->wantToTest(sprintf($this->getMessage($adapter), 'offsetUnset()')); + $I->wantToTest( + sprintf( + $this->getMessage($adapter), + 'offsetUnset()' + ) + ); + $config = $this->getConfig($adapter); - $actual = $config->offsetExists('database'); - $I->assertTrue($actual); + $I->assertTrue( + $config->offsetExists('database') + ); $config->offsetUnset('database'); - $actual = $config->offsetGet('database'); - $I->assertNull($actual); + + $I->assertNull( + $config->offsetGet('database') + ); } /** @@ -309,12 +379,19 @@ private function checkOffsetUnset(UnitTester $I, string $adapter = '') */ private function checkPath(UnitTester $I, string $adapter = '') { - $I->wantToTest(sprintf($this->getMessage($adapter), 'path()')); + $I->wantToTest( + sprintf( + $this->getMessage($adapter), + 'path()' + ) + ); + $config = $this->getConfig($adapter); - $expected = 'yeah'; - $actual = $config->path('test.parent.property2'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'yeah', + $config->path('test.parent.property2') + ); } /** @@ -328,12 +405,19 @@ private function checkPath(UnitTester $I, string $adapter = '') */ private function checkPathDefault(UnitTester $I, string $adapter = '') { - $I->wantToTest(sprintf($this->getMessage($adapter), 'path() - default')); + $I->wantToTest( + sprintf( + $this->getMessage($adapter), + 'path() - default' + ) + ); + $config = $this->getConfig($adapter); - $expected = 'Unknown'; - $actual = $config->path('test.parent.property3', 'Unknown'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'Unknown', + $config->path('test.parent.property3', 'Unknown') + ); } /** @@ -347,24 +431,33 @@ private function checkPathDefault(UnitTester $I, string $adapter = '') */ private function checkSetPathDelimiter(UnitTester $I, string $adapter = '') { - $I->wantToTest(sprintf($this->getMessage($adapter), 'setPathDelimiter()')); + $I->wantToTest( + sprintf( + $this->getMessage($adapter), + 'setPathDelimiter()' + ) + ); + $config = $this->getConfig($adapter); $existing = $config->getPathDelimiter(); - $expected = 'yeah'; - $actual = $config->path('test.parent.property2', 'Unknown'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'yeah', + $config->path('test.parent.property2', 'Unknown') + ); $config->setPathDelimiter('/'); - $expected = 'Unknown'; - $actual = $config->path('test.parent.property2', 'Unknown'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'Unknown', + $config->path('test.parent.property2', 'Unknown') + ); - $expected = 'yeah'; - $actual = $config->path('test/parent/property2', 'Unknown'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'yeah', + $config->path('test/parent/property2', 'Unknown') + ); $config->setPathDelimiter($existing); } @@ -380,11 +473,18 @@ private function checkSetPathDelimiter(UnitTester $I, string $adapter = '') */ private function checkToArray(UnitTester $I, string $adapter = '') { - $I->wantToTest(sprintf($this->getMessage($adapter), 'toArray()')); + $I->wantToTest( + sprintf( + $this->getMessage($adapter), + 'toArray()' + ) + ); + $config = $this->getConfig($adapter); - $expected = $this->config; - $actual = $config->toArray(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $this->config, + $config->toArray() + ); } } diff --git a/tests/_data/fixtures/Traits/CookieTrait.php b/tests/_data/fixtures/Traits/CookieTrait.php index da5db4c616d..8cee7076b14 100644 --- a/tests/_data/fixtures/Traits/CookieTrait.php +++ b/tests/_data/fixtures/Traits/CookieTrait.php @@ -53,8 +53,23 @@ protected function getCookie($name) foreach ($headers as $header) { if (strpos($header, 'Set-Cookie: ') === 0) { - $value = str_replace('&', urlencode('&'), substr($header, 12)); - parse_str(current(explode(';', $value, 1)), $pair); + $value = str_replace( + '&', + urlencode('&'), + substr($header, 12) + ); + + parse_str( + current( + explode( + ';', + $value, + 1 + ) + ), + $pair + ); + $cookies = array_merge_recursive($cookies, $pair); } } diff --git a/tests/_data/fixtures/Traits/Db/MysqlTrait.php b/tests/_data/fixtures/Traits/Db/MysqlTrait.php index a6b599d3cac..fbeae8b82c2 100644 --- a/tests/_data/fixtures/Traits/Db/MysqlTrait.php +++ b/tests/_data/fixtures/Traits/Db/MysqlTrait.php @@ -73,7 +73,9 @@ protected function getSchemaName(): string protected function getExpectedColumns(): array { $result = []; + $columns = $this->getColumns(); + foreach ($columns as $index => $array) { $result[$index] = Column::__set_state($array); } diff --git a/tests/_data/fixtures/Traits/Db/PostgresqlTrait.php b/tests/_data/fixtures/Traits/Db/PostgresqlTrait.php index 59ee38aab5d..0ed8cd0a1a1 100644 --- a/tests/_data/fixtures/Traits/Db/PostgresqlTrait.php +++ b/tests/_data/fixtures/Traits/Db/PostgresqlTrait.php @@ -69,7 +69,9 @@ protected function getSchemaName(): string protected function getExpectedColumns(): array { $result = []; + $columns = $this->getColumns(); + foreach ($columns as $index => $array) { $result[$index] = Column::__set_state($array); } diff --git a/tests/_data/fixtures/Traits/DiTrait.php b/tests/_data/fixtures/Traits/DiTrait.php index b4cf11fc0a0..076677df0c9 100644 --- a/tests/_data/fixtures/Traits/DiTrait.php +++ b/tests/_data/fixtures/Traits/DiTrait.php @@ -78,6 +78,7 @@ protected function getAndSetModelsCacheFile() 'cacheDir' => cacheFolder(), ] ); + $this->container->set('modelsCache', $cache); return $cache; @@ -98,7 +99,15 @@ protected function getAndSetModelsCacheFileLibmemcached() ], ]; - $cache = new Libmemcached(new Data(['lifetime' => 3600]), $config); + $cache = new Libmemcached( + new Data( + [ + 'lifetime' => 3600, + ] + ), + $config + ); + $this->container->set('modelsCache', $cache); return $cache; @@ -110,7 +119,9 @@ protected function getAndSetModelsCacheFileLibmemcached() protected function newDi() { Di::reset(); + $this->container = new Di(); + Di::setDefault($this->container); } @@ -120,7 +131,9 @@ protected function newDi() protected function setNewCliFactoryDefault() { Di::reset(); + $this->container = $this->newCliFactoryDefault(); + Di::setDefault($this->container); } @@ -185,7 +198,10 @@ protected function setCliConsole() */ protected function setDiAnnotations() { - $this->container->set('annotations', new AnnotationsMemory()); + $this->container->set( + 'annotations', + new AnnotationsMemory() + ); } /** @@ -197,6 +213,7 @@ protected function setDiCrypt() 'crypt', function () { $crypt = new Crypt(); + $crypt->setKey('cryptkeycryptkey'); return $crypt; @@ -209,7 +226,10 @@ function () { */ protected function setDiEscaper() { - $this->container->set('escaper', Escaper::class); + $this->container->set( + 'escaper', + Escaper::class + ); } /** @@ -217,7 +237,10 @@ protected function setDiEscaper() */ protected function setDiEventsManager() { - $this->container->set('eventsManager', EventsManager::class); + $this->container->set( + 'eventsManager', + EventsManager::class + ); } /** @@ -240,7 +263,10 @@ function () { */ protected function setDiModelsManager() { - $this->container->setShared('modelsManager', ModelsManager::class); + $this->container->setShared( + 'modelsManager', + ModelsManager::class + ); } /** @@ -248,7 +274,10 @@ protected function setDiModelsManager() */ protected function setDiModelsMetadata() { - $this->container->setShared('modelsMetadata', MetadataMemory::class); + $this->container->setShared( + 'modelsMetadata', + MetadataMemory::class + ); } /** @@ -256,7 +285,10 @@ protected function setDiModelsMetadata() */ protected function setDiMysql() { - $this->container->setShared('db', $this->newDiMysql()); + $this->container->setShared( + 'db', + $this->newDiMysql() + ); } /** @@ -280,7 +312,10 @@ protected function newDiMysql() */ protected function setDiResponse() { - $this->container->set('response', Response::class); + $this->container->set( + 'response', + Response::class + ); } /** @@ -288,7 +323,10 @@ protected function setDiResponse() */ protected function setDiRequest() { - $this->container->set('request', Request::class); + $this->container->set( + 'request', + Request::class + ); } /** @@ -300,6 +338,7 @@ protected function setDiSessionFiles() 'session', function () { $manager = new SessionManager(); + $manager->setHandler( new SessionFiles( [ @@ -322,6 +361,7 @@ protected function setDiSessionLibmemcached() 'session', function () { $manager = new SessionManager(); + $manager->setHandler( new SessionLibmemcached( [ @@ -350,7 +390,10 @@ protected function setDiSessionNoop() 'session', function () { $manager = new SessionManager(); - $manager->setHandler(new SessionNoop()); + + $manager->setHandler( + new SessionNoop() + ); return $manager; } @@ -366,7 +409,10 @@ protected function setDiSessionRedis() 'session', function () { $manager = new SessionManager(); - $manager->setHandler(new SessionRedis()); + + $manager->setHandler( + new SessionRedis() + ); return $manager; } @@ -378,7 +424,10 @@ function () { */ protected function setDiSqlite() { - $this->container->set('db', $this->newDiSqlite()); + $this->container->set( + 'db', + $this->newDiSqlite() + ); } /** @@ -402,6 +451,7 @@ protected function setDiUrl() 'url', function () { $url = new Url(); + $url->setBaseUri('/'); return $url; @@ -418,7 +468,10 @@ protected function setDiView() 'view', function () { $view = new View(); - $view->setViewsDir(dataFolder('fixtures/views')); + + $view->setViewsDir( + dataFolder('fixtures/views') + ); return $view; } @@ -434,6 +487,7 @@ protected function setDiViewSimple() 'viewSimple', function () { $view = new Simple(); + $view->setViewsDir(dataFolder('fixtures/views/')); return $view; @@ -458,7 +512,9 @@ protected function setupPostgres() protected function setNewFactoryDefault() { Di::reset(); + $this->container = $this->newFactoryDefault(); + Di::setDefault($this->container); } @@ -475,7 +531,10 @@ protected function newFactoryDefault() */ protected function setDiPostgresql() { - $this->container->set('db', $this->newDiPostgresql()); + $this->container->set( + 'db', + $this->newDiPostgresql() + ); } /** diff --git a/tests/_data/fixtures/Traits/LoggerTrait.php b/tests/_data/fixtures/Traits/LoggerTrait.php index 4b4d231e84c..f19bc452f35 100644 --- a/tests/_data/fixtures/Traits/LoggerTrait.php +++ b/tests/_data/fixtures/Traits/LoggerTrait.php @@ -24,10 +24,6 @@ */ trait LoggerTrait { - /** - * @param UnitTester $I - * @param string $level - */ protected function runLoggerFile(UnitTester $I, string $level) { $logPath = outputFolder('tests/logs/'); diff --git a/tests/_data/fixtures/Traits/RedisTrait.php b/tests/_data/fixtures/Traits/RedisTrait.php index 33214d8249a..0a501bf881f 100644 --- a/tests/_data/fixtures/Traits/RedisTrait.php +++ b/tests/_data/fixtures/Traits/RedisTrait.php @@ -26,6 +26,7 @@ trait RedisTrait public function _before(UnitTester $I) { $I->checkExtensionIsLoaded('redis'); + $this->options = [ 'host' => env('DATA_REDIS_HOST'), 'port' => env('DATA_REDIS_PORT'), diff --git a/tests/_data/fixtures/Traits/RouterTrait.php b/tests/_data/fixtures/Traits/RouterTrait.php index 14f3f00d110..a6acd0bafd9 100644 --- a/tests/_data/fixtures/Traits/RouterTrait.php +++ b/tests/_data/fixtures/Traits/RouterTrait.php @@ -56,9 +56,13 @@ protected function getRouter($defaultRoutes = true) $router = new Router($defaultRoutes); $di = new Di; - $di->setShared('request', function () { - return new Request; - }); + + $di->setShared( + 'request', + function () { + return new Request; + } + ); $router->setDI($di); @@ -78,10 +82,15 @@ protected function getRouteAndSetRouteMethod($router, array $data) $methodName = $data['methodName']; if (isset($data[1])) { - return $router->$methodName($data[0], $data[1]); + return $router->$methodName( + $data[0], + $data[1] + ); } - return $router->$methodName($data[0]); + return $router->$methodName( + $data[0] + ); } /** @@ -100,7 +109,9 @@ protected function getRouterAndSetRoutesAndHostNames(array $settings, $defaultRo $route = $this->getRouteAndSetRouteMethod($router, $data); if (isset($data['hostname'])) { - $route->setHostname($data['hostname']); + $route->setHostname( + $data['hostname'] + ); } } diff --git a/tests/_data/fixtures/Traits/TagHelperTrait.php b/tests/_data/fixtures/Traits/TagHelperTrait.php index 4f0ab54162b..218f06d629c 100644 --- a/tests/_data/fixtures/Traits/TagHelperTrait.php +++ b/tests/_data/fixtures/Traits/TagHelperTrait.php @@ -30,13 +30,23 @@ trait TagHelperTrait */ public function tagField(UnitTester $I) { - $I->wantToTest(sprintf('Tag - %s() - parameters', $this->function)); + $I->wantToTest( + sprintf( + 'Tag - %s() - parameters', + $this->function + ) + ); + $tag = new Tag(); - $tag->setDI($this->container); - $options = [ + $tag->setDI( + $this->container + ); + + $options = [ 'class' => 'x_class', ]; + $expected = 'testFieldParameter($I, $tag, 'x_name', $this->function, $options, $expected); @@ -76,16 +86,26 @@ abstract protected function testFieldParameter( */ public function tagFieldParameterWithId(UnitTester $I) { - $I->wantToTest(sprintf('Tag - %s() - parameters with id', $this->function)); + $I->wantToTest( + sprintf( + 'Tag - %s() - parameters with id', + $this->function + ) + ); + $tag = new Tag(); - $tag->setDI($this->container); - $options = [ + $tag->setDI( + $this->container + ); + + $options = [ 'name' => 'x_name', 'id' => 'x_id', 'class' => 'x_class', 'size' => '10', ]; + $expected = 'wantToTest(sprintf('Tag - %s() - setAttribute()', $this->function)); + $I->wantToTest( + sprintf( + 'Tag - %s() - setAttribute()', + $this->function + ) + ); + $tag = new Tag(); - $tag->setDI($this->container); - $options = [ + $tag->setDI( + $this->container + ); + + $options = [ 'name' => 'x_name', 'class' => 'x_class', 'size' => '10', ]; - $expected = 'inputType . '" id="x_name" name="x_name" value="x_value" class="x_class" size="10"'; if ($this->inputType === 'radio' || $this->inputType === 'checkbox') { $expected .= ' checked="checked"'; @@ -129,18 +158,26 @@ public function tagFieldWithSetAttribute(UnitTester $I) */ public function tagFieldWithSetAttributeElementNotPresent(UnitTester $I) { - $I->wantToTest(sprintf('Tag - %s() - setAttribute() element not present', $this->function)); + $I->wantToTest( + sprintf( + 'Tag - %s() - setAttribute() element not present', + $this->function + ) + ); + $tag = new Tag(); - $tag->setDI($this->container); + + $tag->setDI( + $this->container + ); $options = [ 'name' => 'x_name', 'class' => 'x_class', 'size' => '10', ]; - $expected = 'inputType . '" id="x_name" name="x_name" value="x_value" class="x_class" size="10"'; if ($this->inputType === 'radio' || $this->inputType === 'checkbox') { $expected .= ' checked="checked"'; diff --git a/tests/_data/fixtures/Traits/TagSetupTrait.php b/tests/_data/fixtures/Traits/TagSetupTrait.php index 0aa80672fb2..60bb00ff290 100644 --- a/tests/_data/fixtures/Traits/TagSetupTrait.php +++ b/tests/_data/fixtures/Traits/TagSetupTrait.php @@ -75,10 +75,16 @@ protected function testFieldParameter( string $set = '' ) { if ($xhtml && 'textArea' !== $function) { - $tag->setDocType(Tag::XHTML10_STRICT); + $tag->setDocType( + Tag::XHTML10_STRICT + ); + $expected .= ' />'; } else { - $tag->setDocType(Tag::HTML5); + $tag->setDocType( + Tag::HTML5 + ); + $expected .= '>'; } diff --git a/tests/_data/fixtures/Traits/ValidationTrait.php b/tests/_data/fixtures/Traits/ValidationTrait.php index d12bf4c998d..f0a414c6ecc 100644 --- a/tests/_data/fixtures/Traits/ValidationTrait.php +++ b/tests/_data/fixtures/Traits/ValidationTrait.php @@ -33,8 +33,14 @@ trait ValidationTrait */ private function checkConstruct(IntegrationTester $I, ValidatorInterface $validator) { - $I->wantToTest($this->getMessage($validator, '__construct()')); - $I->assertInstanceOf(ValidatorInterface::class, $validator); + $I->wantToTest( + $this->getMessage($validator, '__construct()') + ); + + $I->assertInstanceOf( + ValidatorInterface::class, + $validator + ); } /** @@ -49,7 +55,10 @@ private function getMessage(ValidatorInterface $validator, string $method): stri { $class = get_class($validator); - return sprintf(str_replace('Phalcon\\', '', $class) . ' - %s', $method); + return sprintf( + str_replace('Phalcon\\', '', $class) . ' - %s', + $method + ); } /** @@ -63,12 +72,19 @@ private function getMessage(ValidatorInterface $validator, string $method): stri */ private function checkGetOption(IntegrationTester $I, ValidatorInterface $validator) { - $I->wantToTest($this->getMessage($validator, 'getOption()')); + $I->wantToTest( + $this->getMessage( + $validator, + 'getOption()' + ) + ); + $validator->setOption('option', 'value'); - $expected = 'value'; - $actual = $validator->getOption('option'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'value', + $validator->getOption('option') + ); } /** @@ -82,12 +98,21 @@ private function checkGetOption(IntegrationTester $I, ValidatorInterface $valida */ private function checkHasOption(IntegrationTester $I, ValidatorInterface $validator) { - $I->wantToTest($this->getMessage($validator, 'hasOption()')); - $actual = $validator->hasOption('option'); - $I->assertFalse($actual); + $I->wantToTest( + $this->getMessage( + $validator, + 'hasOption()' + ) + ); + + $I->assertFalse( + $validator->hasOption('option') + ); - $actual = $validator->hasOption('message'); - $I->assertTrue($actual); + + $I->assertTrue( + $validator->hasOption('message') + ); } /** @@ -101,11 +126,18 @@ private function checkHasOption(IntegrationTester $I, ValidatorInterface $valida */ private function checkSetOption(IntegrationTester $I, ValidatorInterface $validator) { - $I->wantToTest($this->getMessage($validator, 'setOption()')); + $I->wantToTest( + $this->getMessage( + $validator, + 'setOption()' + ) + ); + $validator->setOption('option', 'value'); - $expected = 'value'; - $actual = $validator->getOption('option'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'value', + $validator->getOption('option') + ); } } diff --git a/tests/_data/fixtures/Traits/ViewTrait.php b/tests/_data/fixtures/Traits/ViewTrait.php index 1e002c05027..c89b0a0ef63 100644 --- a/tests/_data/fixtures/Traits/ViewTrait.php +++ b/tests/_data/fixtures/Traits/ViewTrait.php @@ -52,7 +52,9 @@ public function _after() protected function renderPartialBuffered(ViewBaseInterface $view, $partial, $expectedParams = null) { ob_start(); + $view->partial($partial, $expectedParams); + ob_clean(); } @@ -66,16 +68,27 @@ protected function renderPartialBuffered(ViewBaseInterface $view, $partial, $exp protected function setParamAndCheckData($errorMessage, $params, $view) { foreach ($params as $param) { - $view->setParamToView($param['paramToView'][0], $param['paramToView'][1]); + $view->setParamToView( + $param['paramToView'][0], + $param['paramToView'][1] + ); $view->start(); - $view->setRenderLevel($param['renderLevel']); - $view->render($param['render'][0], $param['render'][1]); + + $view->setRenderLevel( + $param['renderLevel'] + ); + + $view->render( + $param['render'][0], + $param['render'][1] + ); + $view->finish(); $this->assertEquals( - $view->getContent(), $param['expected'], + $view->getContent(), $errorMessage ); } @@ -84,15 +97,23 @@ protected function setParamAndCheckData($errorMessage, $params, $view) protected function clearCache() { if (!file_exists(env('PATH_CACHE'))) { - mkdir(env('PATH_CACHE')); + mkdir( + env('PATH_CACHE') + ); } - foreach (new DirectoryIterator(env('PATH_CACHE')) as $item) { + $items = new DirectoryIterator( + env('PATH_CACHE') + ); + + foreach ($items as $item) { if ($item->isDir()) { continue; } - unlink($item->getPathname()); + unlink( + $item->getPathname() + ); } } } diff --git a/tests/_data/fixtures/controllers/MicroController.php b/tests/_data/fixtures/controllers/MicroController.php index 8daeaff2332..cd516085423 100644 --- a/tests/_data/fixtures/controllers/MicroController.php +++ b/tests/_data/fixtures/controllers/MicroController.php @@ -63,7 +63,9 @@ public function anotherFiveAction() public function returnResponseAction() { $response = new Response(); + $response->setContent("test"); + return $response; } } diff --git a/tests/_data/fixtures/models/Abonnes.php b/tests/_data/fixtures/models/Abonnes.php index f11ab9ec29a..52edaa44634 100644 --- a/tests/_data/fixtures/models/Abonnes.php +++ b/tests/_data/fixtures/models/Abonnes.php @@ -32,7 +32,10 @@ public function initialize() public function beforeValidation() { if ($this->courrierElectronique == 'marina@hotmail.com') { - $this->appendMessage(new Message('Désolé Marina, mais vous n\'êtes pas autorisé ici')); + $this->appendMessage( + new Message('Désolé Marina, mais vous n\'êtes pas autorisé ici') + ); + return false; } } @@ -41,7 +44,10 @@ public function beforeDelete() { if ($this->courrierElectronique == 'fuego@hotmail.com') { //Sorry this cannot be deleted - $this->appendMessage(new Message('Désolé, ce ne peut pas être supprimé')); + $this->appendMessage( + new Message('Désolé, ce ne peut pas être supprimé') + ); + return false; } } @@ -50,41 +56,76 @@ public function validation() { $validator = new Validation(); - $validator->add('creeA', new PresenceOfValidator([ - 'message' => "La date de création est nécessaire", - ])); - - $validator->add('courrierElectronique', new EmailValidator([ - 'field' => '', - 'message' => 'Le courrier électronique est invalide', - ])); - - $validator->add('statut', new ExclusionInValidator([ - 'domain' => ['X', 'Z'], - 'message' => 'L\'état ne doit être "X" ou "Z"', - ])); - - $validator->add('statut', new InclusionInValidator([ - 'domain' => ['P', 'I', 'w'], - 'message' => 'L\'état doit être "P", "I" ou "w"', - ])); - - $validator->add('courrierElectronique', new UniquenessValidator([ - 'message' => 'Le courrier électronique doit être unique', - 'model' => $this, - ])); - - $validator->add('statut', new RegexValidator([ - 'pattern' => '/[A-Z]/', - 'message' => "L'état ne correspond pas à l'expression régulière", - ])); - - $validator->add('courrierElectronique', new StringLengthValidator([ - 'min' => '7', - 'max' => '50', - 'messageMinimum' => "Le courrier électronique est trop court", - 'messageMaximum' => "Le courrier électronique est trop long", - ])); + $validator->add( + 'creeA', + new PresenceOfValidator( + [ + 'message' => "La date de création est nécessaire", + ] + ) + ); + + $validator->add( + 'courrierElectronique', + new EmailValidator( + [ + 'field' => '', + 'message' => 'Le courrier électronique est invalide', + ] + ) + ); + + $validator->add( + 'statut', + new ExclusionInValidator( + [ + 'domain' => ['X', 'Z'], + 'message' => 'L\'état ne doit être "X" ou "Z"', + ] + ) + ); + + $validator->add( + 'statut', + new InclusionInValidator( + [ + 'domain' => ['P', 'I', 'w'], + 'message' => 'L\'état doit être "P", "I" ou "w"', + ] + ) + ); + + $validator->add( + 'courrierElectronique', + new UniquenessValidator( + [ + 'message' => 'Le courrier électronique doit être unique', + 'model' => $this, + ] + ) + ); + + $validator->add( + 'statut', + new RegexValidator( + [ + 'pattern' => '/[A-Z]/', + 'message' => "L'état ne correspond pas à l'expression régulière", + ] + ) + ); + + $validator->add( + 'courrierElectronique', + new StringLengthValidator( + [ + 'min' => '7', + 'max' => '50', + 'messageMinimum' => "Le courrier électronique est trop court", + 'messageMaximum' => "Le courrier électronique est trop long", + ] + ) + ); return $this->validate($validator); } @@ -98,5 +139,4 @@ public function columnMap() 'status' => 'statut', ]; } - } diff --git a/tests/_data/fixtures/models/Cacheable/Model.php b/tests/_data/fixtures/models/Cacheable/Model.php index e970cedad41..f52e05f012f 100644 --- a/tests/_data/fixtures/models/Cacheable/Model.php +++ b/tests/_data/fixtures/models/Cacheable/Model.php @@ -18,6 +18,7 @@ class Model extends PhalconModel public static function findFirst($parameters = null) { $parameters = self::getCacheableParams($parameters); + return parent::findFirst($parameters); } @@ -28,10 +29,12 @@ public static function getCacheableParams($parameters) } if (isset($parameters['di'])) { - unset ($parameters['di']); + unset($parameters['di']); } - $key = md5(get_called_class() . serialize($parameters)); + $key = md5( + get_called_class() . serialize($parameters) + ); if (!is_array($parameters)) { $parameters = [$parameters]; @@ -48,6 +51,7 @@ public static function getCacheableParams($parameters) public static function find($parameters = null) { $parameters = self::getCacheableParams($parameters); + return parent::find($parameters); } } diff --git a/tests/_data/fixtures/models/Customers.php b/tests/_data/fixtures/models/Customers.php index 39174bcdc9f..09d77ac4cc4 100644 --- a/tests/_data/fixtures/models/Customers.php +++ b/tests/_data/fixtures/models/Customers.php @@ -34,10 +34,18 @@ class Customers extends Model public $created_at; protected $protected_field; - private $private_field; + private $private_field; public function initialize() { - $this->hasOne('customer_id', Users::class, 'id', ['alias' => 'user', 'reusable' => true]); + $this->hasOne( + 'customer_id', + Users::class, + 'id', + [ + 'alias' => 'user', + 'reusable' => true, + ] + ); } } diff --git a/tests/_data/fixtures/models/Deles.php b/tests/_data/fixtures/models/Deles.php index 0b8291b0a65..9f2d38820b3 100644 --- a/tests/_data/fixtures/models/Deles.php +++ b/tests/_data/fixtures/models/Deles.php @@ -27,11 +27,15 @@ public function initialize() { $this->setSource("parts"); - $this->hasMany('code', RobottersDeles::class, 'delesCode', [ - 'foreignKey' => [ - 'message' => 'Deles cannot be deleted because is referenced by a Robotter', - ], - ]); + $this->hasMany( + 'code', + RobottersDeles::class, + 'delesCode', + [ + 'foreignKey' => [ + 'message' => 'Deles cannot be deleted because is referenced by a Robotter', + ], + ] + ); } - } diff --git a/tests/_data/fixtures/models/Dynamic/Personers.php b/tests/_data/fixtures/models/Dynamic/Personers.php index f8452c70ed4..f27175eb293 100644 --- a/tests/_data/fixtures/models/Dynamic/Personers.php +++ b/tests/_data/fixtures/models/Dynamic/Personers.php @@ -34,7 +34,9 @@ class Personers extends PhalconModel public function initialize() { $this->setSource('personas'); + $this->useDynamicUpdate(true); + $this->addBehavior( new SoftDelete( [ diff --git a/tests/_data/fixtures/models/Dynamic/Robots.php b/tests/_data/fixtures/models/Dynamic/Robots.php index c3dfb00a758..695f42fbd82 100644 --- a/tests/_data/fixtures/models/Dynamic/Robots.php +++ b/tests/_data/fixtures/models/Dynamic/Robots.php @@ -32,7 +32,11 @@ class Robots extends PhalconModel public function initialize() { - $this->hasMany('id', RobotsParts::class, 'robots_id'); + $this->hasMany( + 'id', + RobotsParts::class, + 'robots_id' + ); $this->useDynamicUpdate(true); } diff --git a/tests/_data/fixtures/models/GossipRobots.php b/tests/_data/fixtures/models/GossipRobots.php index 6ca4057d890..c4ee6e3f729 100644 --- a/tests/_data/fixtures/models/GossipRobots.php +++ b/tests/_data/fixtures/models/GossipRobots.php @@ -15,7 +15,6 @@ class GossipRobots extends Model { - public $trace; public function initialize() @@ -31,6 +30,7 @@ public function beforeValidation() protected function _talk($completeMethod) { $method = explode('::', $completeMethod); + if (!isset($this->trace[$method[1]][get_class($this)])) { $this->trace[$method[1]][get_class($this)] = 1; } else { @@ -81,19 +81,21 @@ public function afterSave() public function beforeCreate() { $this->_talk(__METHOD__); + return false; } public function beforeDelete() { $this->_talk(__METHOD__); + return false; } public function notSaved() { $this->_talk(__METHOD__); + return false; } - } diff --git a/tests/_data/fixtures/models/Language.php b/tests/_data/fixtures/models/Language.php index ba70f38ff83..8ed918c7cee 100644 --- a/tests/_data/fixtures/models/Language.php +++ b/tests/_data/fixtures/models/Language.php @@ -28,10 +28,18 @@ public function initialize() $this->setSource("language"); $this->hasMany( - ['lang', 'locale'], + [ + 'lang', + 'locale', + ], LanguageI18n::class, - ['from_lang', 'from_locale'], - ['alias' => 'translations'] + [ + 'from_lang', + 'from_locale', + ], + [ + 'alias' => 'translations', + ] ); } } diff --git a/tests/_data/fixtures/models/LanguageI18n.php b/tests/_data/fixtures/models/LanguageI18n.php index 460b6aa1af8..c281a70262b 100644 --- a/tests/_data/fixtures/models/LanguageI18n.php +++ b/tests/_data/fixtures/models/LanguageI18n.php @@ -31,14 +31,18 @@ public function initialize() ['from_lang', 'from_lang'], Language::class, ['lang', 'locale'], - ['alias' => 'Origin'] + [ + 'alias' => 'Origin', + ] ); $this->belongsTo( ['lang', 'locale'], Language::class, ['lang', 'locale'], - ['alias' => 'Target'] + [ + 'alias' => 'Target', + ] ); } } diff --git a/tests/_data/fixtures/models/ModelWithStringField.php b/tests/_data/fixtures/models/ModelWithStringField.php index 95d94e1e242..c5fed70e5f6 100644 --- a/tests/_data/fixtures/models/ModelWithStringField.php +++ b/tests/_data/fixtures/models/ModelWithStringField.php @@ -31,13 +31,17 @@ public function initialize() public function allowEmptyStringValue() { - $this->allowEmptyStringValues([ - 'field', - ]); + $this->allowEmptyStringValues( + [ + 'field', + ] + ); } public function disallowEmptyStringValue() { - $this->allowEmptyStringValues([]); + $this->allowEmptyStringValues( + [] + ); } } diff --git a/tests/_data/fixtures/models/News/Subscribers.php b/tests/_data/fixtures/models/News/Subscribers.php index f989df48512..30a9319e931 100644 --- a/tests/_data/fixtures/models/News/Subscribers.php +++ b/tests/_data/fixtures/models/News/Subscribers.php @@ -21,16 +21,24 @@ public function initialize() { $this->setSource("subscriptores"); - $this->addBehavior(new Timestampable([ - 'beforeCreate' => [ - 'field' => 'created_at', - 'format' => 'Y-m-d H:i:s', - ], - ])); + $this->addBehavior( + new Timestampable( + [ + 'beforeCreate' => [ + 'field' => 'created_at', + 'format' => 'Y-m-d H:i:s', + ], + ] + ) + ); - $this->addBehavior(new SoftDelete([ - 'field' => 'status', - 'value' => 'D', - ])); + $this->addBehavior( + new SoftDelete( + [ + 'field' => 'status', + 'value' => 'D', + ] + ) + ); } } diff --git a/tests/_data/fixtures/models/Packages.php b/tests/_data/fixtures/models/Packages.php index 4eb20aa2e8c..4306948473c 100644 --- a/tests/_data/fixtures/models/Packages.php +++ b/tests/_data/fixtures/models/Packages.php @@ -34,7 +34,9 @@ public function initialize() ['reference_id', 'reference_type_id'], PackageDetails::class, ['reference_id', 'reference_type_id'], - ['alias' => 'details'] + [ + 'alias' => 'details', + ] ); } } diff --git a/tests/_data/fixtures/models/Parts.php b/tests/_data/fixtures/models/Parts.php index 27894163400..bfb45cb9e08 100644 --- a/tests/_data/fixtures/models/Parts.php +++ b/tests/_data/fixtures/models/Parts.php @@ -15,14 +15,17 @@ class Parts extends Model { - public function initialize() { - $this->hasMany('id', RobotsParts::class, 'parts_id', [ - 'foreignKey' => [ - 'message' => 'Parts cannot be deleted because is referenced by a Robot', - ], - ]); + $this->hasMany( + 'id', + RobotsParts::class, + 'parts_id', + [ + 'foreignKey' => [ + 'message' => 'Parts cannot be deleted because is referenced by a Robot', + ], + ] + ); } - } diff --git a/tests/_data/fixtures/models/Parts2.php b/tests/_data/fixtures/models/Parts2.php index f5032043548..923843e1307 100644 --- a/tests/_data/fixtures/models/Parts2.php +++ b/tests/_data/fixtures/models/Parts2.php @@ -20,10 +20,15 @@ public function initialize() { $eventsManager = new Manager(); - $eventsManager->attach('model', function ($event, $robot) { - return true; - }); + $eventsManager->attach( + 'model', + function ($event, $robot) { + return true; + } + ); + $this->setEventsManager($eventsManager); + $this->setSource('parts'); } } diff --git a/tests/_data/fixtures/models/Personers.php b/tests/_data/fixtures/models/Personers.php index fc920f287a8..8bf53c89378 100644 --- a/tests/_data/fixtures/models/Personers.php +++ b/tests/_data/fixtures/models/Personers.php @@ -36,5 +36,4 @@ public function columnMap() 'estado' => 'status', ]; } - } diff --git a/tests/_data/fixtures/models/Pessoas.php b/tests/_data/fixtures/models/Pessoas.php index 09d2534063b..0d88e9ae79b 100644 --- a/tests/_data/fixtures/models/Pessoas.php +++ b/tests/_data/fixtures/models/Pessoas.php @@ -36,5 +36,4 @@ public function columnMap() 'estado' => 'estado', ]; } - } diff --git a/tests/_data/fixtures/models/Relations/Deles.php b/tests/_data/fixtures/models/Relations/Deles.php index a4e2982ee37..a65d1b6e9b2 100644 --- a/tests/_data/fixtures/models/Relations/Deles.php +++ b/tests/_data/fixtures/models/Relations/Deles.php @@ -27,11 +27,15 @@ public function initialize() { $this->setSource("parts"); - $this->hasMany('code', RobottersDeles::class, 'delesCode', [ - 'foreignKey' => [ - 'message' => 'Deles cannot be deleted because is referenced by a Robotter', - ], - ]); + $this->hasMany( + 'code', + RobottersDeles::class, + 'delesCode', + [ + 'foreignKey' => [ + 'message' => 'Deles cannot be deleted because is referenced by a Robotter', + ], + ] + ); } - } diff --git a/tests/_data/fixtures/models/Relations/M2MRobots.php b/tests/_data/fixtures/models/Relations/M2MRobots.php index 7f1b8b2ad9e..deb6e2b7ef7 100644 --- a/tests/_data/fixtures/models/Relations/M2MRobots.php +++ b/tests/_data/fixtures/models/Relations/M2MRobots.php @@ -19,6 +19,13 @@ public function initialize() { $this->setSource("m2m_robots"); - $this->hasManyToMany('id', M2MRobotsParts::class, 'robots_id', 'parts_id', 'M2MParts', 'id'); + $this->hasManyToMany( + 'id', + M2MRobotsParts::class, + 'robots_id', + 'parts_id', + M2MParts::class, + 'id' + ); } } diff --git a/tests/_data/fixtures/models/Relations/RelationsParts.php b/tests/_data/fixtures/models/Relations/RelationsParts.php index d26adadff64..20545c07759 100644 --- a/tests/_data/fixtures/models/Relations/RelationsParts.php +++ b/tests/_data/fixtures/models/Relations/RelationsParts.php @@ -19,10 +19,15 @@ public function initialize() { $this->setSource("parts"); - $this->hasMany('id', RelationsRobotsParts::class, 'parts_id', [ - 'foreignKey' => [ - 'message' => 'Parts cannot be deleted because is referenced by a Robot', - ], - ]); + $this->hasMany( + 'id', + RelationsRobotsParts::class, + 'parts_id', + [ + 'foreignKey' => [ + 'message' => 'Parts cannot be deleted because is referenced by a Robot', + ], + ] + ); } } diff --git a/tests/_data/fixtures/models/Relations/RelationsRobots.php b/tests/_data/fixtures/models/Relations/RelationsRobots.php index cd73aafd8d5..dd19c02a2eb 100644 --- a/tests/_data/fixtures/models/Relations/RelationsRobots.php +++ b/tests/_data/fixtures/models/Relations/RelationsRobots.php @@ -19,9 +19,15 @@ public function initialize() { $this->setSource("robots"); - $this->hasMany('id', RelationsRobotsParts::class, 'robots_id', [ - 'foreignKey' => true, - ]); + $this->hasMany( + 'id', + RelationsRobotsParts::class, + 'robots_id', + [ + 'foreignKey' => true, + ] + ); + $this->hasManyToMany( 'id', RelationsRobotsParts::class, diff --git a/tests/_data/fixtures/models/Relations/RelationsRobotsParts.php b/tests/_data/fixtures/models/Relations/RelationsRobotsParts.php index 9d29e0389e9..080a5cb7c0f 100644 --- a/tests/_data/fixtures/models/Relations/RelationsRobotsParts.php +++ b/tests/_data/fixtures/models/Relations/RelationsRobotsParts.php @@ -19,13 +19,24 @@ public function initialize() { $this->setSource("robots_parts"); - $this->belongsTo('parts_id', RelationsParts::class, 'id', [ - 'foreignKey' => true, - ]); - $this->belongsTo('robots_id', RelationsRobots::class, 'id', [ - 'foreignKey' => [ - 'message' => 'The robot code does not exist', - ], - ]); + $this->belongsTo( + 'parts_id', + RelationsParts::class, + 'id', + [ + 'foreignKey' => true, + ] + ); + + $this->belongsTo( + 'robots_id', + RelationsRobots::class, + 'id', + [ + 'foreignKey' => [ + 'message' => 'The robot code does not exist', + ], + ] + ); } } diff --git a/tests/_data/fixtures/models/Relations/Robotters.php b/tests/_data/fixtures/models/Relations/Robotters.php index 13b7c9513fe..cfb72440779 100644 --- a/tests/_data/fixtures/models/Relations/Robotters.php +++ b/tests/_data/fixtures/models/Relations/Robotters.php @@ -32,8 +32,13 @@ public function initialize() { $this->setSource("robots"); - $this->hasMany('code', RobottersDeles::class, 'robottersCode', [ - 'foreignKey' => true, - ]); + $this->hasMany( + 'code', + RobottersDeles::class, + 'robottersCode', + [ + 'foreignKey' => true, + ] + ); } } diff --git a/tests/_data/fixtures/models/Relations/RobottersDeles.php b/tests/_data/fixtures/models/Relations/RobottersDeles.php index bb243537b4f..16b6cab26aa 100644 --- a/tests/_data/fixtures/models/Relations/RobottersDeles.php +++ b/tests/_data/fixtures/models/Relations/RobottersDeles.php @@ -28,14 +28,24 @@ public function initialize() { $this->setSource("robots_parts"); - $this->belongsTo('delesCode', Deles::class, 'code', [ - 'foreignKey' => true, - ]); + $this->belongsTo( + 'delesCode', + Deles::class, + 'code', + [ + 'foreignKey' => true, + ] + ); - $this->belongsTo('robottersCode', Robotters::class, 'code', [ - 'foreignKey' => [ - 'message' => 'The robotters code does not exist', - ], - ]); + $this->belongsTo( + 'robottersCode', + Robotters::class, + 'code', + [ + 'foreignKey' => [ + 'message' => 'The robotters code does not exist', + ], + ] + ); } } diff --git a/tests/_data/fixtures/models/Relations/Some/Deles.php b/tests/_data/fixtures/models/Relations/Some/Deles.php index 1980ca16ec9..406794f93e9 100644 --- a/tests/_data/fixtures/models/Relations/Some/Deles.php +++ b/tests/_data/fixtures/models/Relations/Some/Deles.php @@ -27,11 +27,15 @@ public function initialize() { $this->setSource("parts"); - $this->hasMany('code', RobottersDeles::class, 'delesCode', [ - 'foreignKey' => [ - 'message' => 'Deles cannot be deleted because is referenced by a Robotter', - ], - ]); + $this->hasMany( + 'code', + RobottersDeles::class, + 'delesCode', + [ + 'foreignKey' => [ + 'message' => 'Deles cannot be deleted because is referenced by a Robotter', + ], + ] + ); } - } diff --git a/tests/_data/fixtures/models/Relations/Some/Parts.php b/tests/_data/fixtures/models/Relations/Some/Parts.php index 71e849efe40..f3ac3be84fe 100644 --- a/tests/_data/fixtures/models/Relations/Some/Parts.php +++ b/tests/_data/fixtures/models/Relations/Some/Parts.php @@ -19,11 +19,15 @@ public function initialize() { $this->setSource("parts"); - $this->hasMany('id', RobotsParts::class, 'parts_id', [ - 'foreignKey' => [ - 'message' => 'Parts cannot be deleted because is referenced by a Robot', - ], - ]); + $this->hasMany( + 'id', + RobotsParts::class, + 'parts_id', + [ + 'foreignKey' => [ + 'message' => 'Parts cannot be deleted because is referenced by a Robot', + ], + ] + ); } - } diff --git a/tests/_data/fixtures/models/Relations/Some/Robots.php b/tests/_data/fixtures/models/Relations/Some/Robots.php index 1c98ab03065..187eef33d77 100644 --- a/tests/_data/fixtures/models/Relations/Some/Robots.php +++ b/tests/_data/fixtures/models/Relations/Some/Robots.php @@ -19,13 +19,21 @@ public function initialize() { $this->setSource("robots"); - $this->hasMany('id', RobotsParts::class, 'robots_id', [ - 'foreignKey' => true, - ]); + $this->hasMany( + 'id', + RobotsParts::class, + 'robots_id', + [ + 'foreignKey' => true, + ] + ); } public function getRobotsParts($arguments = null) { - return $this->getRelated(RobotsParts::class, $arguments); + return $this->getRelated( + RobotsParts::class, + $arguments + ); } } diff --git a/tests/_data/fixtures/models/Relations/Some/RobotsParts.php b/tests/_data/fixtures/models/Relations/Some/RobotsParts.php index cd42218472d..ad60e240361 100644 --- a/tests/_data/fixtures/models/Relations/Some/RobotsParts.php +++ b/tests/_data/fixtures/models/Relations/Some/RobotsParts.php @@ -19,13 +19,24 @@ public function initialize() { $this->setSource("robots_parts"); - $this->belongsTo('parts_id', Parts::class, 'id', [ - 'foreignKey' => true, - ]); - $this->belongsTo('robots_id', Robots::class, 'id', [ - 'foreignKey' => [ - 'message' => 'The robot code does not exist', - ], - ]); + $this->belongsTo( + 'parts_id', + Parts::class, + 'id', + [ + 'foreignKey' => true, + ] + ); + + $this->belongsTo( + 'robots_id', + Robots::class, + 'id', + [ + 'foreignKey' => [ + 'message' => 'The robot code does not exist', + ], + ] + ); } } diff --git a/tests/_data/fixtures/models/Relations/Some/Robotters.php b/tests/_data/fixtures/models/Relations/Some/Robotters.php index 5b1cd968bad..a106b40d928 100644 --- a/tests/_data/fixtures/models/Relations/Some/Robotters.php +++ b/tests/_data/fixtures/models/Relations/Some/Robotters.php @@ -32,13 +32,21 @@ public function initialize() { $this->setSource("robots"); - $this->hasMany('code', RobottersDeles::class, 'robottersCode', [ - 'foreignKey' => true, - ]); + $this->hasMany( + 'code', + RobottersDeles::class, + 'robottersCode', + [ + 'foreignKey' => true, + ] + ); } public function getRobottersDeles($arguments = null) { - return $this->getRelated(RobottersDeles::class, $arguments); + return $this->getRelated( + RobottersDeles::class, + $arguments + ); } } diff --git a/tests/_data/fixtures/models/Relations/Some/RobottersDeles.php b/tests/_data/fixtures/models/Relations/Some/RobottersDeles.php index 9cd295c20b9..49a07c40c2b 100644 --- a/tests/_data/fixtures/models/Relations/Some/RobottersDeles.php +++ b/tests/_data/fixtures/models/Relations/Some/RobottersDeles.php @@ -28,14 +28,24 @@ public function initialize() { $this->setSource("robots_parts"); - $this->belongsTo('delesCode', Deles::class, 'code', [ - 'foreignKey' => true, - ]); + $this->belongsTo( + 'delesCode', + Deles::class, + 'code', + [ + 'foreignKey' => true, + ] + ); - $this->belongsTo('robottersCode', Robotters::class, 'code', [ - 'foreignKey' => [ - 'message' => 'The robotters code does not exist', - ], - ]); + $this->belongsTo( + 'robottersCode', + Robotters::class, + 'code', + [ + 'foreignKey' => [ + 'message' => 'The robotters code does not exist', + ], + ] + ); } } diff --git a/tests/_data/fixtures/models/RobotsParts.php b/tests/_data/fixtures/models/RobotsParts.php index 968ebfbefba..5c40418e570 100644 --- a/tests/_data/fixtures/models/RobotsParts.php +++ b/tests/_data/fixtures/models/RobotsParts.php @@ -15,17 +15,26 @@ class RobotsParts extends Model { - public function initialize() { - $this->belongsTo('parts_id', Parts::class, 'id', [ - 'foreignKey' => true, - ]); - $this->belongsTo('robots_id', Robots::class, 'id', [ - 'foreignKey' => [ - 'message' => 'The robot code does not exist', - ], - ]); - } + $this->belongsTo( + 'parts_id', + Parts::class, + 'id', + [ + 'foreignKey' => true, + ] + ); + $this->belongsTo( + 'robots_id', + Robots::class, + 'id', + [ + 'foreignKey' => [ + 'message' => 'The robot code does not exist', + ], + ] + ); + } } diff --git a/tests/_data/fixtures/models/Robotters.php b/tests/_data/fixtures/models/Robotters.php index 336b18a19c0..4dc9aa36606 100644 --- a/tests/_data/fixtures/models/Robotters.php +++ b/tests/_data/fixtures/models/Robotters.php @@ -32,9 +32,13 @@ public function initialize() { $this->setSource("robots"); - $this->hasMany('code', RobottersDeles::class, 'robottersCode', [ - 'foreignKey' => true, - ]); + $this->hasMany( + 'code', + RobottersDeles::class, + 'robottersCode', + [ + 'foreignKey' => true, + ] + ); } - } diff --git a/tests/_data/fixtures/models/RobottersDeles.php b/tests/_data/fixtures/models/RobottersDeles.php index 7771814b125..809800605e3 100644 --- a/tests/_data/fixtures/models/RobottersDeles.php +++ b/tests/_data/fixtures/models/RobottersDeles.php @@ -28,14 +28,24 @@ public function initialize() { $this->setSource("robots_parts"); - $this->belongsTo('delesCode', Deles::class, 'code', [ - 'foreignKey' => true, - ]); + $this->belongsTo( + 'delesCode', + Deles::class, + 'code', + [ + 'foreignKey' => true, + ] + ); - $this->belongsTo('robottersCode', Robotters::class, 'code', [ - 'foreignKey' => [ - 'message' => 'The robotters code does not exist', - ], - ]); + $this->belongsTo( + 'robottersCode', + Robotters::class, + 'code', + [ + 'foreignKey' => [ + 'message' => 'The robotters code does not exist', + ], + ] + ); } } diff --git a/tests/_data/fixtures/models/Snapshot/Parts.php b/tests/_data/fixtures/models/Snapshot/Parts.php index a6fd0297b08..da029a2a094 100644 --- a/tests/_data/fixtures/models/Snapshot/Parts.php +++ b/tests/_data/fixtures/models/Snapshot/Parts.php @@ -17,7 +17,12 @@ class Parts extends Model { public function initialize() { - $this->hasMany('id', RobotsParts::class, 'robots_id'); + $this->hasMany( + 'id', + RobotsParts::class, + 'robots_id' + ); + $this->keepSnapshots(true); } } diff --git a/tests/_data/fixtures/models/Snapshot/Robots.php b/tests/_data/fixtures/models/Snapshot/Robots.php index ef274bbe98c..a5bdfc5302b 100644 --- a/tests/_data/fixtures/models/Snapshot/Robots.php +++ b/tests/_data/fixtures/models/Snapshot/Robots.php @@ -17,7 +17,12 @@ class Robots extends Model { public function initialize() { - $this->hasMany('id', RobotsParts::class, 'robots_id'); + $this->hasMany( + 'id', + RobotsParts::class, + 'robots_id' + ); + $this->keepSnapshots(true); } } diff --git a/tests/_data/fixtures/models/Snapshot/RobotsParts.php b/tests/_data/fixtures/models/Snapshot/RobotsParts.php index bba093288e0..6459dd87a89 100644 --- a/tests/_data/fixtures/models/Snapshot/RobotsParts.php +++ b/tests/_data/fixtures/models/Snapshot/RobotsParts.php @@ -15,10 +15,18 @@ class RobotsParts extends Model { - public function initialize() { - $this->belongsTo('robots_id', Robots::class, 'id'); - $this->belongsTo('parts_id', Parts::class, 'id'); + $this->belongsTo( + 'robots_id', + Robots::class, + 'id' + ); + + $this->belongsTo( + 'parts_id', + Parts::class, + 'id' + ); } } diff --git a/tests/_data/fixtures/models/Snapshot/Robotters.php b/tests/_data/fixtures/models/Snapshot/Robotters.php index b68d2812e89..dc9a13220d2 100644 --- a/tests/_data/fixtures/models/Snapshot/Robotters.php +++ b/tests/_data/fixtures/models/Snapshot/Robotters.php @@ -32,7 +32,12 @@ public function initialize() { $this->setSource("robots"); - $this->hasMany('code', RobottersDeles::class, 'robottersCode'); + $this->hasMany( + 'code', + RobottersDeles::class, + 'robottersCode' + ); + $this->keepSnapshots(true); } } diff --git a/tests/_data/fixtures/models/Snapshot/Subscribers.php b/tests/_data/fixtures/models/Snapshot/Subscribers.php index 4d4ac5bff1f..9bc47dc004b 100644 --- a/tests/_data/fixtures/models/Snapshot/Subscribers.php +++ b/tests/_data/fixtures/models/Snapshot/Subscribers.php @@ -29,16 +29,24 @@ public function initialize() $this->keepSnapshots(true); - $this->addBehavior(new Timestampable([ - 'beforeCreate' => [ - 'field' => 'created_at', - 'format' => 'Y-m-d H:i:s', - ], - ])); + $this->addBehavior( + new Timestampable( + [ + 'beforeCreate' => [ + 'field' => 'created_at', + 'format' => 'Y-m-d H:i:s', + ], + ] + ) + ); - $this->addBehavior(new SoftDelete([ - 'field' => 'status', - 'value' => 'D', - ])); + $this->addBehavior( + new SoftDelete( + [ + 'field' => 'status', + 'value' => 'D', + ] + ) + ); } } diff --git a/tests/_data/fixtures/models/Some/Deles.php b/tests/_data/fixtures/models/Some/Deles.php index 8a8a6c2fe88..bd3a5ae35e5 100644 --- a/tests/_data/fixtures/models/Some/Deles.php +++ b/tests/_data/fixtures/models/Some/Deles.php @@ -27,11 +27,15 @@ public function initialize() { $this->setSource("parts"); - $this->hasMany('code', RobottersDeles::class, 'delesCode', [ - 'foreignKey' => [ - 'message' => 'Deles cannot be deleted because is referenced by a Robotter', - ], - ]); + $this->hasMany( + 'code', + RobottersDeles::class, + 'delesCode', + [ + 'foreignKey' => [ + 'message' => 'Deles cannot be deleted because is referenced by a Robotter', + ], + ] + ); } - } diff --git a/tests/_data/fixtures/models/Some/Parts.php b/tests/_data/fixtures/models/Some/Parts.php index 5b8422f59f1..4f6fbfaf74b 100644 --- a/tests/_data/fixtures/models/Some/Parts.php +++ b/tests/_data/fixtures/models/Some/Parts.php @@ -19,11 +19,15 @@ public function initialize() { $this->setSource("parts"); - $this->hasMany('id', RobotsParts::class, 'parts_id', [ - 'foreignKey' => [ - 'message' => 'Parts cannot be deleted because is referenced by a Robot', - ], - ]); + $this->hasMany( + 'id', + RobotsParts::class, + 'parts_id', + [ + 'foreignKey' => [ + 'message' => 'Parts cannot be deleted because is referenced by a Robot', + ], + ] + ); } - } diff --git a/tests/_data/fixtures/models/Some/Products.php b/tests/_data/fixtures/models/Some/Products.php index 3bf836aad7b..9fa940817d9 100644 --- a/tests/_data/fixtures/models/Some/Products.php +++ b/tests/_data/fixtures/models/Some/Products.php @@ -58,5 +58,4 @@ public function metaData() MetaData::MODELS_AUTOMATIC_DEFAULT_UPDATE => [], ]; } - } diff --git a/tests/_data/fixtures/models/Some/RobotsParts.php b/tests/_data/fixtures/models/Some/RobotsParts.php index e01eb222af1..4a3d83916a4 100644 --- a/tests/_data/fixtures/models/Some/RobotsParts.php +++ b/tests/_data/fixtures/models/Some/RobotsParts.php @@ -19,13 +19,24 @@ public function initialize() { $this->setSource("robots_parts"); - $this->belongsTo('parts_id', Parts::class, 'id', [ - 'foreignKey' => true, - ]); - $this->belongsTo('robots_id', Robots::class, 'id', [ - 'foreignKey' => [ - 'message' => 'The robot code does not exist', - ], - ]); + $this->belongsTo( + 'parts_id', + Parts::class, + 'id', + [ + 'foreignKey' => true, + ] + ); + + $this->belongsTo( + 'robots_id', + Robots::class, + 'id', + [ + 'foreignKey' => [ + 'message' => 'The robot code does not exist', + ], + ] + ); } } diff --git a/tests/_data/fixtures/models/Some/Robotters.php b/tests/_data/fixtures/models/Some/Robotters.php index e7013d9c8a0..5ac01997ac5 100644 --- a/tests/_data/fixtures/models/Some/Robotters.php +++ b/tests/_data/fixtures/models/Some/Robotters.php @@ -32,13 +32,21 @@ public function initialize() { $this->setSource("robots"); - $this->hasMany('code', RobottersDeles::class, 'robottersCode', [ - 'foreignKey' => true, - ]); + $this->hasMany( + 'code', + RobottersDeles::class, + 'robottersCode', + [ + 'foreignKey' => true, + ] + ); } public function getRobottersDeles($arguments = null) { - return $this->getRelated(RobottersDeles::class, $arguments); + return $this->getRelated( + RobottersDeles::class, + $arguments + ); } } diff --git a/tests/_data/fixtures/models/Some/RobottersDeles.php b/tests/_data/fixtures/models/Some/RobottersDeles.php index ee8d101ff1c..54207d82ad1 100644 --- a/tests/_data/fixtures/models/Some/RobottersDeles.php +++ b/tests/_data/fixtures/models/Some/RobottersDeles.php @@ -28,14 +28,24 @@ public function initialize() { $this->setSource("robots_parts"); - $this->belongsTo('delesCode', Deles::class, 'code', [ - 'foreignKey' => true, - ]); + $this->belongsTo( + 'delesCode', + Deles::class, + 'code', + [ + 'foreignKey' => true, + ] + ); - $this->belongsTo('robottersCode', Robotters::class, 'code', [ - 'foreignKey' => [ - 'message' => 'The robotters code does not exist', - ], - ]); + $this->belongsTo( + 'robottersCode', + Robotters::class, + 'code', + [ + 'foreignKey' => [ + 'message' => 'The robotters code does not exist', + ], + ] + ); } } diff --git a/tests/_data/fixtures/models/Store/Parts.php b/tests/_data/fixtures/models/Store/Parts.php index 957d674a57c..90ed7785243 100644 --- a/tests/_data/fixtures/models/Store/Parts.php +++ b/tests/_data/fixtures/models/Store/Parts.php @@ -19,8 +19,13 @@ public function initialize() { $this->setConnectionService('dbTwo'); - $this->hasMany('id', RobotsParts::class, 'parts_id', [ - 'alias' => 'RobotParts', - ]); + $this->hasMany( + 'id', + RobotsParts::class, + 'parts_id', + [ + 'alias' => 'RobotParts', + ] + ); } } diff --git a/tests/_data/fixtures/models/Store/Robots.php b/tests/_data/fixtures/models/Store/Robots.php index 5aeab5af6a4..7d4ce1d1f0c 100644 --- a/tests/_data/fixtures/models/Store/Robots.php +++ b/tests/_data/fixtures/models/Store/Robots.php @@ -17,11 +17,15 @@ class Robots extends Model { public function initialize() { - $this->setConnectionService('dbOne'); - $this->hasMany('id', RobotsParts::class, 'robots_id', [ - 'alias' => 'RobotParts', - ]); + $this->hasMany( + 'id', + RobotsParts::class, + 'robots_id', + [ + 'alias' => 'RobotParts', + ] + ); } } diff --git a/tests/_data/fixtures/models/Store/RobotsParts.php b/tests/_data/fixtures/models/Store/RobotsParts.php index 2c368102dfe..039347f0c9f 100644 --- a/tests/_data/fixtures/models/Store/RobotsParts.php +++ b/tests/_data/fixtures/models/Store/RobotsParts.php @@ -19,11 +19,22 @@ public function initialize() { $this->setConnectionService('dbOne'); - $this->belongsTo('parts_id', Parts::class, 'id', [ - 'alias' => 'Part', - ]); - $this->belongsTo('robots_id', Robots::class, 'id', [ - 'alias' => 'Robot', - ]); + $this->belongsTo( + 'parts_id', + Parts::class, + 'id', + [ + 'alias' => 'Part', + ] + ); + + $this->belongsTo( + 'robots_id', + Robots::class, + 'id', + [ + 'alias' => 'Robot', + ] + ); } } diff --git a/tests/_data/fixtures/models/Subscriptores.php b/tests/_data/fixtures/models/Subscriptores.php index 1652bd0828c..be966e6bd87 100644 --- a/tests/_data/fixtures/models/Subscriptores.php +++ b/tests/_data/fixtures/models/Subscriptores.php @@ -28,7 +28,10 @@ class Subscriptores extends Model public function beforeValidation() { if ($this->email == 'marina@hotmail.com') { - $this->appendMessage(new Message('Sorry Marina, but you are not allowed here')); + $this->appendMessage( + new Message('Sorry Marina, but you are not allowed here') + ); + return false; } } @@ -36,7 +39,10 @@ public function beforeValidation() public function beforeDelete() { if ($this->email == 'fuego@hotmail.com') { - $this->appendMessage(new Message('Sorry this cannot be deleted')); + $this->appendMessage( + new Message('Sorry this cannot be deleted') + ); + return false; } } @@ -45,30 +51,61 @@ public function validation() { $validator = new Validation(); - $validator->add('created_at', new PresenceOfValidator()); + $validator->add( + 'created_at', + new PresenceOfValidator() + ); - $validator->add('email', new StringLengthValidator([ - 'min' => '7', - 'max' => '50', - ])); + $validator->add( + 'email', + new StringLengthValidator( + [ + 'min' => '7', + 'max' => '50', + ] + ) + ); - $validator->add('email', new EmailValidator()); + $validator->add( + 'email', + new EmailValidator() + ); - $validator->add('status', new ExclusionInValidator([ - 'domain' => ['X', 'Z'], - ])); + $validator->add( + 'status', + new ExclusionInValidator( + [ + 'domain' => ['X', 'Z'], + ] + ) + ); - $validator->add('status', new InclusionInValidator([ - 'domain' => ['P', 'I', 'w'], - ])); + $validator->add( + 'status', + new InclusionInValidator( + [ + 'domain' => ['P', 'I', 'w'], + ] + ) + ); - $validator->add('email', new UniquenessValidator([ - 'model' => $this, - ])); + $validator->add( + 'email', + new UniquenessValidator( + [ + 'model' => $this, + ] + ) + ); - $validator->add('status', new RegexValidator([ - 'pattern' => '/[A-Z]/', - ])); + $validator->add( + 'status', + new RegexValidator( + [ + 'pattern' => '/[A-Z]/', + ] + ) + ); return $this->validate($validator); } diff --git a/tests/_data/fixtures/models/Validation/Robots.php b/tests/_data/fixtures/models/Validation/Robots.php index 099529073ca..a5e69554011 100644 --- a/tests/_data/fixtures/models/Validation/Robots.php +++ b/tests/_data/fixtures/models/Validation/Robots.php @@ -41,6 +41,7 @@ public function initialize() public function validation() { $validation = new Validation(); + $validation->add( 'name', new StringLength( diff --git a/tests/_data/fixtures/models/Validation/Subscriptores.php b/tests/_data/fixtures/models/Validation/Subscriptores.php index 918d0069a7f..ec25a90b2b4 100644 --- a/tests/_data/fixtures/models/Validation/Subscriptores.php +++ b/tests/_data/fixtures/models/Validation/Subscriptores.php @@ -33,7 +33,9 @@ class Subscriptores extends Model public function beforeValidation() { if ($this->email == 'marina@hotmail.com') { - $this->appendMessage(new Message('Sorry Marina, but you are not allowed here')); + $this->appendMessage( + new Message('Sorry Marina, but you are not allowed here') + ); return false; } @@ -44,7 +46,9 @@ public function beforeValidation() public function beforeDelete() { if ($this->email == 'fuego@hotmail.com') { - $this->appendMessage(new Message('Sorry this cannot be deleted')); + $this->appendMessage( + new Message('Sorry this cannot be deleted') + ); return false; } @@ -55,6 +59,7 @@ public function beforeDelete() public function validation() { $validator = new Validation(); + $validator ->add('created_at', new PresenceOf()) ->add('email', new StringLength(['min' => '7', 'max' => '50'])) diff --git a/tests/_data/fixtures/modules/backend/Module.php b/tests/_data/fixtures/modules/backend/Module.php index 00db78b8a28..93f46934e79 100644 --- a/tests/_data/fixtures/modules/backend/Module.php +++ b/tests/_data/fixtures/modules/backend/Module.php @@ -32,11 +32,17 @@ public function registerAutoloaders(DiInterface $di = null) public function registerServices(DiInterface $di) { - $di->set('view', function () { - $view = new View(); - $view->setViewsDir(dataFolder('fixtures/modules/backend/views/')); + $di->set( + 'view', + function () { + $view = new View(); - return $view; - }); + $view->setViewsDir( + dataFolder('fixtures/modules/backend/views/') + ); + + return $view; + } + ); } } diff --git a/tests/_data/fixtures/modules/frontend/Module.php b/tests/_data/fixtures/modules/frontend/Module.php index 3eb6885bb94..fe6d8a76947 100644 --- a/tests/_data/fixtures/modules/frontend/Module.php +++ b/tests/_data/fixtures/modules/frontend/Module.php @@ -32,11 +32,17 @@ public function registerAutoloaders(DiInterface $di = null) public function registerServices(DiInterface $di) { - $di->set('view', function () { - $view = new View(); - $view->setViewsDir(dataFolder('fixtures/modules/frontend/views/')); + $di->set( + 'view', + function () { + $view = new View(); - return $view; - }); + $view->setViewsDir( + dataFolder('fixtures/modules/frontend/views/') + ); + + return $view; + } + ); } } diff --git a/tests/_data/fixtures/resultsets/Stats.php b/tests/_data/fixtures/resultsets/Stats.php index a5d50edffb4..b37ffec8c67 100644 --- a/tests/_data/fixtures/resultsets/Stats.php +++ b/tests/_data/fixtures/resultsets/Stats.php @@ -15,4 +15,6 @@ use Phalcon\Mvc\Model\Resultset\Simple; -class Stats extends Simple {} +class Stats extends Simple +{ +} diff --git a/tests/_data/fixtures/tasks/Issue787Task.php b/tests/_data/fixtures/tasks/Issue787Task.php index bb8bcf309b4..4cce43bd245 100644 --- a/tests/_data/fixtures/tasks/Issue787Task.php +++ b/tests/_data/fixtures/tasks/Issue787Task.php @@ -10,7 +10,9 @@ public function beforeExecuteRoute() { $this->dispatcher; $this->dispatcher; + self::$output .= "beforeExecuteRoute" . PHP_EOL; + return true; } diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php index 566a1d93faf..f3413a8cc86 100644 --- a/tests/_support/AcceptanceTester.php +++ b/tests/_support/AcceptanceTester.php @@ -1,5 +1,6 @@ Data::class, @@ -83,6 +83,7 @@ public function __construct(ModuleContainer $container, array $config = null) ]; $this->projectPath = Configuration::projectDir(); + $this->config = array_merge($defaults, $config); parent::__construct($container); @@ -93,9 +94,17 @@ public function __construct(ModuleContainer $container, array $config = null) */ public function _initialize() { - $this->initializeCachePath($this->config['cache_dir']); - $this->initializeFrontend($this->config['frontend']); - $this->initializeBackend($this->config['backend']); + $this->initializeCachePath( + $this->config['cache_dir'] + ); + + $this->initializeFrontend( + $this->config['frontend'] + ); + + $this->initializeBackend( + $this->config['backend'] + ); } /** @@ -121,17 +130,25 @@ public function haveFrontendAdapter($className, array $config = null) $config = array_merge($defaults, $config); $this->_reconfigure($config); - $this->debugSection('Frontend', get_class($this->frontend)); + + $this->debugSection( + 'Frontend', + get_class($this->frontend) + ); } public function dontSeeCacheStarted() { - $this->assertFalse($this->backend->isStarted()); + $this->assertFalse( + $this->backend->isStarted() + ); } public function seeCacheStarted() { - $this->assertTrue($this->backend->isStarted()); + $this->assertTrue( + $this->backend->isStarted() + ); } /** @@ -144,7 +161,9 @@ public function seeCacheStarted() */ public function haveInCacheStorage($key, $content = null, $lifetime = null, $stopBuffer = true) { - $this->assertTrue($this->backend->save($key, $content, $lifetime, $stopBuffer)); + $this->assertTrue( + $this->backend->save($key, $content, $lifetime, $stopBuffer) + ); } /** @@ -152,7 +171,9 @@ public function haveInCacheStorage($key, $content = null, $lifetime = null, $sto */ public function deleteCacheData($keyName) { - $this->assertTrue($this->backend->delete($keyName)); + $this->assertTrue( + $this->backend->delete($keyName) + ); } /** @@ -189,23 +210,39 @@ public function dontSeeCacheFound($filename, $path = '') */ public function seeInCacheStorage($key, $value = null, $lifetime = null) { - $this->assertTrue($this->backend->exists($key, $lifetime)); - $this->amInPath($this->config['cache_dir']); - $this->seeFileFound($this->config['prefix'] . $this->backend->getKey($key)); + $this->assertTrue( + $this->backend->exists($key, $lifetime) + ); + + $this->amInPath( + $this->config['cache_dir'] + ); + + $this->seeFileFound( + $this->config['prefix'] . $this->backend->getKey($key) + ); $actual = $this->backend->get($key, $lifetime); $this->debugSection('Value', $actual); $serializeCallback = $this->serializeCallback; + if (null === $value || !is_callable($serializeCallback)) { return; } $serialized = call_user_func_array($serializeCallback, [$value]); - $this->assertEquals($serialized, $this->file); - $this->assertEquals($serialized, $this->frontend->beforeStore($value)); + $this->assertEquals( + $serialized, + $this->file + ); + + $this->assertEquals( + $serialized, + $this->frontend->beforeStore($value) + ); } /** @@ -233,10 +270,13 @@ protected function initializeFrontend($className) } $supportedFrontends = $this->getSupportedFrontends(); + $this->assertArrayHasKey($className, $supportedFrontends); if (isset($supportedFrontends[$className]['validate_cb'])) { - call_user_func($supportedFrontends[$className]['validate_cb']); + call_user_func( + $supportedFrontends[$className]['validate_cb'] + ); } if (isset($supportedFrontends[$className]['serialize_cb'])) { @@ -247,7 +287,11 @@ protected function initializeFrontend($className) $this->unserializeCallback = $supportedFrontends[$className]['unserialize_cb']; } - $adapter = new $className(['lifetime' => $this->config['lifetime']]); + $adapter = new $className( + [ + 'lifetime' => $this->config['lifetime'], + ] + ); $this->config['frontend'] = $className; $this->frontend = $adapter; @@ -255,10 +299,13 @@ protected function initializeFrontend($className) protected function initializeBackend($className) { - $adapter = new FileBackend($this->frontend, [ - 'cacheDir' => $this->config['cache_dir'], - 'prefix' => $this->config['prefix'], - ]); + $adapter = new FileBackend( + $this->frontend, + [ + 'cacheDir' => $this->config['cache_dir'], + 'prefix' => $this->config['prefix'], + ] + ); $this->config['backend'] = $className; $this->backend = $adapter; diff --git a/tests/_support/Helper/PhalconLibmemcached.php b/tests/_support/Helper/PhalconLibmemcached.php index b9e60e48ece..e179c5f963e 100644 --- a/tests/_support/Helper/PhalconLibmemcached.php +++ b/tests/_support/Helper/PhalconLibmemcached.php @@ -40,7 +40,10 @@ class PhalconLibmemcached extends Module public function _initialize() { if (!class_exists('\Memcached')) { - throw new ModuleException(__CLASS__, 'The memcached extension is not loaded'); + throw new ModuleException( + __CLASS__, + 'The memcached extension is not loaded' + ); } $this->config = [ @@ -136,7 +139,9 @@ public function haveInLibmemcached($key, $value, $expiration = null) $this->memcached->set($key, $value, intval($expiration)); if ($this->memcached->getResultCode() !== \Memcached::RES_SUCCESS) { - $this->fail("[{$this->memcached->getResultCode()}] Unable to store the '$key' in the Memcached"); + $this->fail( + "[{$this->memcached->getResultCode()}] Unable to store the '$key' in the Memcached" + ); } } @@ -163,6 +168,7 @@ public function dontSeeInLibmemcached($key, $value = null) } $actual = $this->memcached->get($key); + $this->debugSection('Value', $actual); if ($value === null) { @@ -177,7 +183,11 @@ public function dontSeeInLibmemcached($key, $value = null) $this->fail("Cannot find key '$key' in the Memcached"); } - $this->assertEquals($value, $actual, "The key '$key' exists in Memcached with the provided value"); + $this->assertEquals( + $value, + $actual, + "The key '$key' exists in Memcached with the provided value" + ); } /** @@ -202,11 +212,16 @@ public function removeFromLibmemcached($key) } $actual = $this->memcached->get($key); + $this->debugSection('Value', $actual); if ($this->memcached->getResultCode() === \Memcached::RES_SUCCESS) { $actual = $this->memcached->delete($key); - $this->assertTrue($actual, "Cannot delete key '$key' from Memcached"); + + $this->assertTrue( + $actual, + "Cannot delete key '$key' from Memcached" + ); } } @@ -233,6 +248,7 @@ public function seeInLibmemcached($key, $value = null) } $actual = $this->memcached->get($key); + $this->debugSection('Value', $actual); if ($this->memcached->getResultCode() !== \Memcached::RES_SUCCESS) { @@ -240,7 +256,11 @@ public function seeInLibmemcached($key, $value = null) } if ($value !== null) { - $this->assertEquals($value, $actual, "Cannot find key '$key' in the Memcached with the provided value"); + $this->assertEquals( + $value, + $actual, + "Cannot find key '$key' in the Memcached with the provided value" + ); } } @@ -251,7 +271,9 @@ public function seeInLibmemcached($key, $value = null) */ protected function connect() { - $this->memcached = new \Memcached($this->config['persistent_id']); + $this->memcached = new \Memcached( + $this->config['persistent_id'] + ); // Persistent memcached pools need to be reconnected if getServerList() is empty if (empty($this->memcached->getServerList())) { @@ -262,7 +284,10 @@ protected function connect() ); if (!$connect) { - throw new ModuleException(__CLASS__, 'Cannot connect to the Memcached server'); + throw new ModuleException( + __CLASS__, + 'Cannot connect to the Memcached server' + ); } } } diff --git a/tests/_support/Helper/Unit.php b/tests/_support/Helper/Unit.php index f26ab1fc81a..3329dee611c 100644 --- a/tests/_support/Helper/Unit.php +++ b/tests/_support/Helper/Unit.php @@ -28,6 +28,7 @@ public function callProtectedMethod($obj, $method) $reflectionClass = new ReflectionClass($obj); $reflectionMethod = $reflectionClass->getMethod($method); + $reflectionMethod->setAccessible(true); if (!is_object($obj)) { @@ -36,9 +37,13 @@ public function callProtectedMethod($obj, $method) // $obj, $method $args = array_slice(func_get_args(), 2); + array_unshift($args, $obj); - return call_user_func_array([$reflectionMethod, 'invoke'], $args); + return call_user_func_array( + [$reflectionMethod, 'invoke'], + $args + ); } /** @@ -104,6 +109,7 @@ public function getProtectedProperty($obj, $prop) $reflection = new ReflectionClass($obj); $property = $reflection->getProperty($prop); + $property->setAccessible(true); return $property->getValue($obj); @@ -121,9 +127,13 @@ public function setProtectedProperty($obj, $prop, $value) $reflection = new ReflectionClass($obj); $property = $reflection->getProperty($prop); + $property->setAccessible(true); $property->setValue($obj, $value); - $this->assertEquals($value, $property->getValue($obj)); + $this->assertEquals( + $value, + $property->getValue($obj) + ); } } diff --git a/tests/_support/IntegrationTester.php b/tests/_support/IntegrationTester.php index 7e103271dc6..7b1ebdf6094 100644 --- a/tests/_support/IntegrationTester.php +++ b/tests/_support/IntegrationTester.php @@ -1,5 +1,6 @@ wantToTest("Cli\Console - __construct()"); + $this->newDi(); //Make sure the Default DI has no services. + $container = $this->newCliFactoryDefault(); $console = $this->newCliConsole(); - $I->assertFalse($console->getDI()->has('dispatcher')); + + $I->assertFalse( + $console->getDI()->has('dispatcher') + ); $console = new CliConsole($container); - $expected = Dispatcher::class; - $actual = $console->getDI()->getShared('dispatcher'); - $I->assertInstanceOf($expected, $actual); + $I->assertInstanceOf( + Dispatcher::class, + $console->getDI()->getShared('dispatcher') + ); } } diff --git a/tests/cli/Cli/Console/GetModuleCest.php b/tests/cli/Cli/Console/GetModuleCest.php index f3683800b1b..f90fc24a1cd 100644 --- a/tests/cli/Cli/Console/GetModuleCest.php +++ b/tests/cli/Cli/Console/GetModuleCest.php @@ -37,26 +37,31 @@ class GetModuleCest public function cliConsoleGetModule(CliTester $I) { $I->wantToTest("Cli\Console - getModule()"); + $console = $this->newCliConsole(); $console->registerModules( [ "frontend" => [ "className" => "Phalcon\\Test\\Modules\\Frontend\\Module", - "path" => __DIR__ . "/../../../_data/modules/frontend/Module.php", + "path" => __DIR__ . "/../../../_data/modules/frontend/Module.php", ], "backend" => [ "className" => "Phalcon\\Test\\Modules\\Backend\\Module", - "path" => __DIR__ . "/../../../_data/modules/backend/Module.php", + "path" => __DIR__ . "/../../../_data/modules/backend/Module.php", ] ] ); + $expected = [ "className" => "Phalcon\\Test\\Modules\\Frontend\\Module", - "path" => __DIR__ . "/../../../_data/modules/frontend/Module.php", + "path" => __DIR__ . "/../../../_data/modules/frontend/Module.php", ]; - $actual = $console->getModule("frontend"); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $expected, + $console->getModule("frontend") + ); $I->expectThrowable( new Exception("Module 'foo' isn't registered in the application container"), diff --git a/tests/cli/Cli/Console/GetModulesCest.php b/tests/cli/Cli/Console/GetModulesCest.php index d84693873d7..f721c2cff22 100644 --- a/tests/cli/Cli/Console/GetModulesCest.php +++ b/tests/cli/Cli/Console/GetModulesCest.php @@ -36,9 +36,12 @@ class GetModulesCest public function cliConsoleGetModules(CliTester $I) { $I->wantToTest("Cli\Console - getModules()"); + $console = $this->newCliConsole(); - $expected = []; - $actual = $console->getModules(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + [], + $console->getModules() + ); } } diff --git a/tests/cli/Cli/Console/GetSetDICest.php b/tests/cli/Cli/Console/GetSetDICest.php index fcfe91b6b93..79858c2eac4 100644 --- a/tests/cli/Cli/Console/GetSetDICest.php +++ b/tests/cli/Cli/Console/GetSetDICest.php @@ -34,13 +34,16 @@ class GetSetDICest public function cliConsoleGetSetDI(CliTester $I) { $I->wantToTest('Cli\Console - getDI()/setDI()'); + $container = $this->newCliFactoryDefault(); $console = $this->newCliConsole(); + $console->setDI($container); - $expected = Dispatcher::class; - $actual = $console->getDI()->getShared('dispatcher'); - $I->assertInstanceOf($expected, $actual); + $I->assertInstanceOf( + Dispatcher::class, + $console->getDI()->getShared('dispatcher') + ); } } diff --git a/tests/cli/Cli/Console/GetSetDefaultModuleCest.php b/tests/cli/Cli/Console/GetSetDefaultModuleCest.php index 5c68c0ec251..f1cc9ff64d7 100644 --- a/tests/cli/Cli/Console/GetSetDefaultModuleCest.php +++ b/tests/cli/Cli/Console/GetSetDefaultModuleCest.php @@ -41,8 +41,12 @@ public function cliConsoleSetGetDefaultModule(CliTester $I) $I->wantToTest("Cli\Console - setDefaultModule()"); $console = $this->newCliConsole(); + $console->setDefaultModule("moduleName"); - $I->assertEquals("moduleName", $console->getDefaultModule()); + $I->assertEquals( + "moduleName", + $console->getDefaultModule() + ); } } diff --git a/tests/cli/Cli/Console/GetSetEventsManagerCest.php b/tests/cli/Cli/Console/GetSetEventsManagerCest.php index d1635298d13..85cd2f9d3ad 100644 --- a/tests/cli/Cli/Console/GetSetEventsManagerCest.php +++ b/tests/cli/Cli/Console/GetSetEventsManagerCest.php @@ -37,12 +37,14 @@ public function cliConsoleGetSetEventsManager(CliTester $I) $I->wantToTest("Cli\Console - setEventsManager()"); $console = $this->newCliConsole(); + $eventsManager = $this->newEventsManager(); $console->setEventsManager($eventsManager); - $expected = Manager::class; - $actual = $console->getEventsManager(); - $I->assertInstanceOf($expected, $actual); + $I->assertInstanceOf( + Manager::class, + $console->getEventsManager() + ); } } diff --git a/tests/cli/Cli/Console/HandleCest.php b/tests/cli/Cli/Console/HandleCest.php index cfb66dea1a4..20ede227c1d 100644 --- a/tests/cli/Cli/Console/HandleCest.php +++ b/tests/cli/Cli/Console/HandleCest.php @@ -36,8 +36,11 @@ public function cliConsoleHandle(CliTester $I) { require_once dataFolder('fixtures/tasks/MainTask.php'); require_once dataFolder('fixtures/tasks/EchoTask.php'); + $I->wantToTest("Cli\Console - handle()"); + $container = $this->newCliFactoryDefault(); + $container->set( 'data', function () { @@ -46,80 +49,122 @@ function () { ); $console = $this->newCliConsole(); + $console->setDI($container); + $dispatcher = $console->getDI()->getShared('dispatcher'); - $console->handle([]); - $expected = 'main'; - $actual = $dispatcher->getTaskName(); - $I->assertEquals($expected, $actual); - $expected = 'main'; - $actual = $dispatcher->getActionName(); - $I->assertEquals($expected, $actual); - $expected = []; - $actual = $dispatcher->getParams(); - $I->assertEquals($expected, $actual); - $expected = 'mainAction'; - $actual = $dispatcher->getReturnedValue(); - $I->assertEquals($expected, $actual); + $console->handle( + [] + ); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'main', + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'mainAction', + $dispatcher->getReturnedValue() + ); + + $console->handle( [ 'task' => 'echo', ] ); - $expected = 'echo'; - $actual = $dispatcher->getTaskName(); - $I->assertEquals($expected, $actual); - $expected = 'main'; - $actual = $dispatcher->getActionName(); - $I->assertEquals($expected, $actual); - $expected = []; - $actual = $dispatcher->getParams(); - $I->assertEquals($expected, $actual); - $expected = 'echoMainAction'; - $actual = $dispatcher->getReturnedValue(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 'echo', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'main', + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'echoMainAction', + $dispatcher->getReturnedValue() + ); + + $console->handle( [ - 'task' => 'main', + 'task' => 'main', 'action' => 'hello', ] ); - $expected = 'main'; - $actual = $dispatcher->getTaskName(); - $I->assertEquals($expected, $actual); - $expected = 'hello'; - $actual = $dispatcher->getActionName(); - $I->assertEquals($expected, $actual); - $expected = []; - $actual = $dispatcher->getParams(); - $I->assertEquals($expected, $actual); - $expected = 'Hello !'; - $actual = $dispatcher->getReturnedValue(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'hello', + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'Hello !', + $dispatcher->getReturnedValue() + ); + + $console->handle( [ - 'task' => 'main', + 'task' => 'main', 'action' => 'hello', 'World', '######', ] ); - $expected = 'main'; - $actual = $dispatcher->getTaskName(); - $I->assertEquals($expected, $actual); - $expected = 'hello'; - $actual = $dispatcher->getActionName(); - $I->assertEquals($expected, $actual); - $expected = ['World', '######']; - $actual = $dispatcher->getParams(); - $I->assertEquals($expected, $actual); - $expected = 'Hello World######'; - $actual = $dispatcher->getReturnedValue(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'hello', + $dispatcher->getActionName() + ); + + $I->assertEquals( + ['World', '######'], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'Hello World######', + $dispatcher->getReturnedValue() + ); } /** @@ -133,40 +178,60 @@ function () { public function cliConsoleHandleModule(CliTester $I) { require_once dataFolder('fixtures/modules/backend/tasks/MainTask.php'); + $I->wantToTest("Cli\Console - handle() - Modules"); + $console = $this->newCliConsole(); + $this->setNewCliFactoryDefault(); - $console->setDI($this->container); + + $console->setDI( + $this->container + ); + $console->registerModules( [ "frontend" => [ "className" => "Phalcon\\Test\\Modules\\Frontend\\Module", - "path" => dataFolder("/fixtures/modules/frontend/Module.php"), + "path" => dataFolder("/fixtures/modules/frontend/Module.php"), ], "backend" => [ "className" => "Phalcon\\Test\\Modules\\Backend\\Module", - "path" => dataFolder("fixtures/modules/backend/Module.php"), - ] + "path" => dataFolder("fixtures/modules/backend/Module.php"), + ], ] ); + $console->dispatcher->setNamespaceName("Phalcon\\Test\\Modules\\Backend\\Tasks"); - $I->expectThrowable(new \Exception("Task Run"), function () use ($console) { - $console->handle([ - "module" => "backend", - "action" => "throw" - ]); - }); + $I->expectThrowable( + new \Exception("Task Run"), + function () use ($console) { + $console->handle( + [ + "module" => "backend", + "action" => "throw", + ] + ); + } + ); + $dispatcher = $console->dispatcher; - $expected = 'main'; - $actual = $dispatcher->getTaskName(); - $I->assertEquals($expected, $actual); - $expected = 'throw'; - $actual = $dispatcher->getActionName(); - $I->assertEquals($expected, $actual); - $expected = 'backend'; - $actual = $dispatcher->getModuleName(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'throw', + $dispatcher->getActionName() + ); + + $I->assertEquals( + 'backend', + $dispatcher->getModuleName() + ); } /** @@ -180,21 +245,33 @@ public function cliConsoleHandleModule(CliTester $I) public function cliConsoleHandleEventBoot(CliTester $I) { $I->wantToTest("Cli\Console - handle() - Events - console:boot"); + $this->setNewCliFactoryDefault(); $this->setDiEventsManager(); + $eventsManager = $this->container->getShared('eventsManager'); + $eventsManager->attach( 'console:boot', function (Event $event, $console) { throw new \Exception("Console Boot Event Fired"); } ); + $console = $this->newCliConsole(); + $console->setDI($this->container); + $console->setEventsManager($eventsManager); - $I->expectThrowable(new \Exception("Console Boot Event Fired"), function () use ($console) { - $console->handle([]); - }); + + $I->expectThrowable( + new \Exception("Console Boot Event Fired"), + function () use ($console) { + $console->handle( + [] + ); + } + ); } /** @@ -208,37 +285,56 @@ function (Event $event, $console) { public function cliConsoleHandleEventBeforeStartModule(CliTester $I) { require_once dataFolder('fixtures/modules/backend/tasks/MainTask.php'); + $I->wantToTest("Cli\Console - handle() - Events - console:beforeStartModule"); + $this->setNewCliFactoryDefault(); $this->setDiEventsManager(); + $eventsManager = $this->container->getShared('eventsManager'); + $console = $this->newCliConsole(); - $console->setDI($this->container); + + $console->setDI( + $this->container + ); + $console->setEventsManager($eventsManager); + $eventsManager->attach( 'console:beforeStartModule', function (Event $event, $console, $moduleName) { throw new \Exception("Console Before Start Module Event Fired"); } ); + $console->registerModules( [ "frontend" => [ "className" => "Phalcon\\Test\\Modules\\Frontend\\Module", - "path" => dataFolder("fixtures/modules/frontend/Module.php"), + "path" => dataFolder("fixtures/modules/frontend/Module.php"), ], "backend" => [ - "className" => "Phalcon\\Test\\Modules\\Backend\\Module" - ] + "className" => "Phalcon\\Test\\Modules\\Backend\\Module", + ], ] ); - $console->dispatcher->setNamespaceName("Phalcon\\Test\\Modules\\Backend\\Tasks"); - $I->expectThrowable(new \Exception("Console Before Start Module Event Fired"), function () use ($console) { - $console->handle([ - "module" => "backend", - "action" => "noop" - ]); - }); + + $console->dispatcher->setNamespaceName( + "Phalcon\\Test\\Modules\\Backend\\Tasks" + ); + + $I->expectThrowable( + new \Exception("Console Before Start Module Event Fired"), + function () use ($console) { + $console->handle( + [ + "module" => "backend", + "action" => "noop", + ] + ); + } + ); } /** @@ -252,36 +348,52 @@ function (Event $event, $console, $moduleName) { public function cliConsoleHandleEventAfterStartModule(CliTester $I) { require_once dataFolder('fixtures/modules/backend/tasks/MainTask.php'); + $I->wantToTest("Cli\Console - handle() - Events - console:afterStartModule"); + $this->setNewCliFactoryDefault(); $this->setDiEventsManager(); + $eventsManager = $this->container->getShared('eventsManager'); + $console = $this->newCliConsole(); - $console->setDI($this->container); + + $console->setDI( + $this->container + ); + $console->setEventsManager($eventsManager); + $console->registerModules( [ "frontend" => [ "className" => "Phalcon\\Test\\Modules\\Frontend\\Module", - "path" => dataFolder("fixtures/modules/frontend/Module.php"), + "path" => dataFolder("fixtures/modules/frontend/Module.php"), ], "backend" => [ - "className" => "Phalcon\\Test\\Modules\\Backend\\Module" - ] + "className" => "Phalcon\\Test\\Modules\\Backend\\Module", + ], ] ); + $eventsManager->attach( 'console:afterStartModule', function (Event $event, $console, $moduleObject) { throw new \Exception("Console After Start Module Event Fired"); } ); - $I->expectThrowable(new \Exception("Console After Start Module Event Fired"), function () use ($console) { - $console->handle([ - "module" => "backend", - "action" => "noop" - ]); - }); + + $I->expectThrowable( + new \Exception("Console After Start Module Event Fired"), + function () use ($console) { + $console->handle( + [ + "module" => "backend", + "action" => "noop" + ] + ); + } + ); } /** @@ -295,12 +407,20 @@ function (Event $event, $console, $moduleObject) { public function cliConsoleHandleEventBeforeHandleTask(CliTester $I) { require_once dataFolder('fixtures/modules/backend/tasks/MainTask.php'); + $I->wantToTest("Cli\Console - handle() - Events - console:beforeHandleTask"); + $this->setNewCliFactoryDefault(); $this->setDiEventsManager(); + $eventsManager = $this->container->getShared('eventsManager'); + $console = $this->newCliConsole(); - $console->setDI($this->container); + + $console->setDI( + $this->container + ); + $console->setEventsManager($eventsManager); $eventsManager->attach( @@ -309,9 +429,15 @@ function (Event $event, $console, $moduleObject) { throw new \Exception("Console Before Handle Task Event Fired"); } ); - $I->expectThrowable(new \Exception("Console Before Handle Task Event Fired"), function () use ($console) { - $console->handle([]); - }); + + $I->expectThrowable( + new \Exception("Console Before Handle Task Event Fired"), + function () use ($console) { + $console->handle( + [] + ); + } + ); } /** * Tests Phalcon\Cli\Console :: handle() @@ -324,36 +450,52 @@ function (Event $event, $console, $moduleObject) { public function cliConsoleHandleEventAfterHandleTask(CliTester $I) { require_once dataFolder('fixtures/modules/backend/tasks/MainTask.php'); + $I->wantToTest("Cli\Console - handle() - Events - console:afterHandleTask"); + $this->setNewCliFactoryDefault(); $this->setDiEventsManager(); + $eventsManager = $this->container->getShared('eventsManager'); + $console = $this->newCliConsole(); - $console->setDI($this->container); + + $console->setDI( + $this->container + ); + $console->setEventsManager($eventsManager); + $eventsManager->attach( 'console:afterHandleTask', function (Event $event, $console, $moduleObject) { throw new \Exception("Console After Handle Task Event Fired"); } ); + $console->registerModules( [ "frontend" => [ - "className" => "Phalcon\\Test\\Modules\\Frontend\\Module", - "path" => dataFolder("fixtures/modules/frontend/Module.php"), + "className" => \Phalcon\Test\Modules\Frontend\Module::class, + "path" => dataFolder("fixtures/modules/frontend/Module.php"), ], "backend" => [ - "className" => "Phalcon\\Test\\Modules\\Backend\\Module" - ] + "className" => \Phalcon\Test\Modules\Backend\Module::class, + ], ] ); - $I->expectThrowable(new \Exception("Console After Handle Task Event Fired"), function () use ($console) { - $console->handle([ - "module" => "backend", - "action" => "noop" - ]); - }); + + $I->expectThrowable( + new \Exception("Console After Handle Task Event Fired"), + function () use ($console) { + $console->handle( + [ + "module" => "backend", + "action" => "noop", + ] + ); + } + ); } /** @@ -369,36 +511,55 @@ function (Event $event, $console, $moduleObject) { public function cliConsoleHandle13724(CliTester $I) { require_once dataFolder('fixtures/modules/backend/tasks/MainTask.php'); + $I->wantToTest("Cli\Console - handle() - Issue #13724"); + $console = $this->newCliConsole(); + $this->setNewCliFactoryDefault(); - $console->setDI($this->container); + + $console->setDI( + $this->container + ); + $console->registerModules( [ "backend" => [ "className" => "Phalcon\\Test\\Modules\\Backend\\Module", - "path" => dataFolder("fixtures/modules/backend/Module.php"), - ] + "path" => dataFolder("fixtures/modules/backend/Module.php"), + ], + ] + ); + + $console->handle( + [ + "module" => "backend", + "action" => "noop", ] ); - $console->handle([ - "module"=>"backend", - "action" => "noop" - ]); + $console = $this->newCliConsole(); + $this->setNewCliFactoryDefault(); - $console->setDI($this->container); + + $console->setDI( + $this->container + ); + $console->registerModules( [ "backend" => [ "className" => "Phalcon\\Test\\Modules\\Backend\\Module", - "path" => dataFolder("fixtures/modules/backend/Module.php"), - ] + "path" => dataFolder("fixtures/modules/backend/Module.php"), + ], + ] + ); + + $console->handle( + [ + "module" => "backend", + "action" => "noop", ] ); - $console->handle([ - "module"=>"backend", - "action" => "noop" - ]); } } diff --git a/tests/cli/Cli/Console/RegisterModulesCest.php b/tests/cli/Cli/Console/RegisterModulesCest.php index 0b43440db0d..83b6b9de21e 100644 --- a/tests/cli/Cli/Console/RegisterModulesCest.php +++ b/tests/cli/Cli/Console/RegisterModulesCest.php @@ -38,39 +38,68 @@ public function cliConsoleRegisterModules(CliTester $I) $I->wantToTest("Cli\Console - registerModules()"); $console = $this->newCliConsole(); + $console->registerModules( [ "frontend" => [ - "className" => "Phalcon\\Test\\Modules\\Frontend\\Module", - "path" => __DIR__ . "/../../../_data/modules/frontend/Module.php", - ] + "className" => \Phalcon\Test\Modules\Frontend\Module::class, + "path" => __DIR__ . "/../../../_data/modules/frontend/Module.php", + ], ] ); - $I->assertCount(1, $console->getModules()); - $I->assertArrayHasKey("frontend", $console->getModules()); + + $I->assertCount( + 1, + $console->getModules() + ); + + $I->assertArrayHasKey( + "frontend", + $console->getModules() + ); $console->registerModules( [ "backend" => [ - "className" => "Phalcon\\Test\\Modules\\Backend\\Module", - "path" => __DIR__ . "/../../../_data/modules/backend/Module.php", - ] + "className" => \Phalcon\Test\Modules\Backend\Module::class, + "path" => __DIR__ . "/../../../_data/modules/backend/Module.php", + ], ] ); - $I->assertCount(1, $console->getModules()); - $I->assertArrayHasKey("backend", $console->getModules()); + + $I->assertCount( + 1, + $console->getModules() + ); + + $I->assertArrayHasKey( + "backend", + $console->getModules() + ); $console->registerModules( [ "frontend" => [ - "className" => "Phalcon\\Test\\Modules\\Frontend\\Module", - "path" => __DIR__ . "/../../../_data/modules/frontend/Module.php", - ] + "className" => \Phalcon\Test\Modules\Frontend\Module::class, + "path" => __DIR__ . "/../../../_data/modules/frontend/Module.php", + ], ], $merge = true ); - $I->assertCount(2, $console->getModules()); - $I->assertArrayHasKey("frontend", $console->getModules()); - $I->assertArrayHasKey("backend", $console->getModules()); + + $I->assertCount( + 2, + $console->getModules() + ); + + $I->assertArrayHasKey( + "frontend", + $console->getModules() + ); + + $I->assertArrayHasKey( + "backend", + $console->getModules() + ); } } diff --git a/tests/cli/Cli/Console/SetArgumentCest.php b/tests/cli/Cli/Console/SetArgumentCest.php index e10da3cf024..b29bd19ec53 100644 --- a/tests/cli/Cli/Console/SetArgumentCest.php +++ b/tests/cli/Cli/Console/SetArgumentCest.php @@ -37,7 +37,9 @@ class SetArgumentCest public function cliConsoleSetArgument(CliTester $I) { require_once dataFolder('fixtures/tasks/MainTask.php'); + $I->wantToTest("Cli\Console - setArgument()"); + $this->setNewCliFactoryDefault(); $this->container->setShared( @@ -50,21 +52,46 @@ function () { ); $console = $this->newCliConsole(); - $console->setDI($this->container); + + $console->setDI( + $this->container + ); $dispatcher = $this->container->getShared("dispatcher"); - $console->setArgument([ - "php", - "--foo=bar", - "-bar", + + $console->setArgument( + [ + "php", + "--foo=bar", + "-bar", + "main", + "hello", + "a", + "B", + ] + )->handle(); + + $I->assertEquals( "main", + $dispatcher->getTaskName() + ); + + $I->assertEquals( "hello", - "a", - "B" - ])->handle(); - $I->assertEquals("main", $dispatcher->getTaskName()); - $I->assertEquals("hello", $dispatcher->getActionName()); - $I->assertEquals(["a", "B"], $dispatcher->getParams()); - $I->assertEquals(["foo" => "bar", "bar" => true], $dispatcher->getOptions()); + $dispatcher->getActionName() + ); + + $I->assertEquals( + ["a", "B"], + $dispatcher->getParams() + ); + + $I->assertEquals( + [ + "foo" => "bar", + "bar" => true, + ], + $dispatcher->getOptions() + ); } } diff --git a/tests/cli/Cli/Console/UnderscoreGetCest.php b/tests/cli/Cli/Console/UnderscoreGetCest.php index 9dce1ded5f5..f7f7245282b 100644 --- a/tests/cli/Cli/Console/UnderscoreGetCest.php +++ b/tests/cli/Cli/Console/UnderscoreGetCest.php @@ -21,7 +21,6 @@ */ class UnderscoreGetCest { - use DiTrait; /** @@ -38,16 +37,23 @@ class UnderscoreGetCest public function cliConsoleUnderscoreGet(CliTester $I) { $I->wantToTest("Cli\Console - __get()"); + $this->setNewCliFactoryDefault(); + $console = $this->newCliConsole(); - $console->setDI($this->container); - $expected = Dispatcher::class; - $actual = $console->dispatcher; - $I->assertInstanceOf($expected, $actual); + $console->setDI( + $this->container + ); + + $I->assertInstanceOf( + Dispatcher::class, + $console->dispatcher + ); - $expected = $this->container; - $actual = $console->di; - $I->assertSame($expected, $actual); + $I->assertSame( + $this->container, + $console->di + ); } } diff --git a/tests/cli/Cli/ConsoleCest.php b/tests/cli/Cli/ConsoleCest.php index 46a1cd45aea..3fd5f3aa902 100644 --- a/tests/cli/Cli/ConsoleCest.php +++ b/tests/cli/Cli/ConsoleCest.php @@ -33,7 +33,9 @@ public function _before(CliTester $I) public function shouldThrowExceptionWhenModuleDoesNotExists(CliTester $I) { $I->expectThrowable( - new ConsoleException("Module 'devtools' isn't registered in the console container"), + new ConsoleException( + "Module 'devtools' isn't registered in the console container" + ), function () { $this->container->set( 'data', @@ -43,7 +45,10 @@ function () { ); $console = new Console(); - $console->setDI($this->container); + + $console->setDI( + $this->container + ); // testing module $console->handle( @@ -61,22 +66,29 @@ function () { public function shouldThrowExceptionWhenTaskDoesNotExists(CliTester $I) { - $I->expectThrowable( - new DispatcherException("Dummy\MainTask handler class cannot be loaded", 2), + $this->container->set( + 'data', function () { - $this->container->set( - 'data', - function () { - return "data"; - } - ); + return "data"; + } + ); - $console = new Console(); - $console->setDI($this->container); - $dispatcher = $console->getDI()->getShared('dispatcher'); + $console = new Console(); - $dispatcher->setDefaultNamespace('Dummy\\'); + $console->setDI( + $this->container + ); + $dispatcher = $console->getDI()->getShared('dispatcher'); + + $dispatcher->setDefaultNamespace('Dummy\\'); + + $I->expectThrowable( + new DispatcherException( + "Dummy\MainTask handler class cannot be loaded", + 2 + ), + function () use ($console) { // testing namespace $console->handle( [ @@ -100,7 +112,10 @@ function () { ); $console = new Console(); - $console->setDI($this->container); + + $console->setDI( + $this->container + ); $expected = [ 'devtools' => [ @@ -111,7 +126,10 @@ function () { $console->registerModules($expected); - $I->assertEquals($expected, $console->getModules()); + $I->assertEquals( + $expected, + $console->getModules() + ); $userModules = [ 'front' => [ @@ -141,7 +159,10 @@ function () { $console->registerModules($userModules, true); - $I->assertEquals($expected, $console->getModules()); + $I->assertEquals( + $expected, + $console->getModules() + ); } public function testIssue787(CliTester $I) @@ -149,11 +170,17 @@ public function testIssue787(CliTester $I) require_once dataFolder('fixtures/tasks/Issue787Task.php'); $dispatcher = new Dispatcher(); - $dispatcher->setDI($this->container); + + $dispatcher->setDI( + $this->container + ); + $this->container->setShared('dispatcher', $dispatcher); $console = new Console(); + $console->setDI($this->container); + $console->handle( [ 'task' => 'issue787', @@ -161,11 +188,14 @@ public function testIssue787(CliTester $I) ] ); - $I->assertTrue(class_exists('Issue787Task')); + $I->assertTrue( + class_exists('Issue787Task') + ); - $actual = \Issue787Task::$output; - $expected = "beforeExecuteRoute" . PHP_EOL . "initialize" . PHP_EOL; - $I->assertEquals($expected, $actual); + $I->assertEquals( + "beforeExecuteRoute" . PHP_EOL . "initialize" . PHP_EOL, + \Issue787Task::$output + ); } public function testArgumentArray(CliTester $I) @@ -177,109 +207,280 @@ public function testArgumentArray(CliTester $I) require_once dataFolder('fixtures/tasks/MainTask.php'); $console = new Console(); - $console->setDI($this->container); + + $console->setDI( + $this->container + ); + $dispatcher = $console->getDI()->getShared('dispatcher'); - $console->setArgument(array( - 'php', - ), false)->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'main'); - $I->assertEquals($dispatcher->getParams(), []); - $I->assertEquals($dispatcher->getReturnedValue(), 'mainAction'); - - $console->setArgument(array( - 'php', - 'echo' - ), false)->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'echo'); - $I->assertEquals($dispatcher->getActionName(), 'main'); - $I->assertEquals($dispatcher->getParams(), []); - $I->assertEquals($dispatcher->getReturnedValue(), 'echoMainAction'); - - $console->setArgument(array( - 'php', + $console->setArgument( + [ + 'php', + ], + false + )->handle(); + + $I->assertEquals( 'main', - 'hello' - ), false)->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'hello'); - $I->assertEquals($dispatcher->getParams(), []); - $I->assertEquals($dispatcher->getReturnedValue(), 'Hello !'); - - $console->setArgument(array( - 'php', + $dispatcher->getTaskName() + ); + + $I->assertEquals( 'main', + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'mainAction', + $dispatcher->getReturnedValue() + ); + + $console->setArgument( + [ + 'php', + 'echo', + ], + false + )->handle(); + + $I->assertEquals( + 'echo', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'main', + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'echoMainAction', + $dispatcher->getReturnedValue() + ); + + $console->setArgument( + [ + 'php', + 'main', + 'hello', + ], + false + )->handle(); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( 'hello', - 'World', - '######' - ), false)->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'hello'); - $I->assertEquals($dispatcher->getParams(), array('World', '######')); - $I->assertEquals($dispatcher->getReturnedValue(), 'Hello World######'); + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'Hello !', + $dispatcher->getReturnedValue() + ); + + $console->setArgument( + [ + 'php', + 'main', + 'hello', + 'World', + '######', + ], + false + )->handle(); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'hello', + $dispatcher->getActionName() + ); + + $I->assertEquals( + ['World', '######'], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'Hello World######', + $dispatcher->getReturnedValue() + ); } public function testArgumentNoShift(CliTester $I) { $console = new Console(); - $console->setDI($this->container); + + $console->setDI( + $this->container + ); + $dispatcher = $console->getDI()->getShared('dispatcher'); - $console->setArgument([], false, false)->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'main'); - $I->assertEquals($dispatcher->getParams(), []); - $I->assertEquals($dispatcher->getReturnedValue(), 'mainAction'); - - $console->setArgument(array( - 'echo' - ), false, false)->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'echo'); - $I->assertEquals($dispatcher->getActionName(), 'main'); - $I->assertEquals($dispatcher->getParams(), []); - $I->assertEquals($dispatcher->getReturnedValue(), 'echoMainAction'); - - $console->setArgument(array( + $console->setArgument( + [], + false, + false + )->handle(); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'main', + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'mainAction', + $dispatcher->getReturnedValue() + ); + + $console->setArgument( + [ + 'echo', + ], + false, + false + )->handle(); + + $I->assertEquals( + 'echo', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'main', + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'echoMainAction', + $dispatcher->getReturnedValue() + ); + + $console->setArgument([ 'main', 'hello' - ), false, false)->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'hello'); - $I->assertEquals($dispatcher->getParams(), []); - $I->assertEquals($dispatcher->getReturnedValue(), 'Hello !'); + ], false, false)->handle(); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'hello', + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'Hello !', + $dispatcher->getReturnedValue() + ); - $console->setArgument(array( + $console->setArgument( + [ + 'main', + 'hello', + 'World', + '######', + ], + false, + false + )->handle(); + + $I->assertEquals( 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( 'hello', - 'World', - '######' - ), false, false)->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'hello'); - $I->assertEquals($dispatcher->getParams(), array('World', '######')); - $I->assertEquals($dispatcher->getReturnedValue(), 'Hello World######'); + $dispatcher->getActionName() + ); + + $I->assertEquals( + ['World', '######'], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'Hello World######', + $dispatcher->getReturnedValue() + ); } public function shouldThrowExceptionWithUnshiftedArguments(CliTester $I) { - $I->expectThrowable( - new DispatcherException('Dummy\MainTask handler class cannot be loaded', 2), - function () { - $console = new Console(); - $console->setDI($this->container); - $dispatcher = $console->getDI()->getShared('dispatcher'); + $console = new Console(); - // testing namespace - $dispatcher->setDefaultNamespace('Dummy\\'); + $console->setDI( + $this->container + ); + + $dispatcher = $console->getDI()->getShared('dispatcher'); + + // testing namespace + $dispatcher->setDefaultNamespace('Dummy\\'); - $console->setArgument(array( - 'main', - 'hello', - 'World', - '!' - ), false, false); + $console->setArgument( + [ + 'main', + 'hello', + 'World', + '!', + ], + false, + false + ); + $I->expectThrowable( + new DispatcherException( + 'Dummy\MainTask handler class cannot be loaded', + 2 + ), + function () use ($console) { $console->handle(); } ); @@ -287,24 +488,34 @@ function () { public function shouldThrowExceptionWithArgumentsAsAnArray(CliTester $I) { - $I->expectThrowable( - new DispatcherException('Dummy\MainTask handler class cannot be loaded', 2), - function () { - $console = new Console(); - $console->setDI($this->container); - $dispatcher = $console->getDI()->getShared('dispatcher'); + $console = new Console(); - // testing namespace - $dispatcher->setDefaultNamespace('Dummy\\'); + $console->setDI( + $this->container + ); + + $dispatcher = $console->getDI()->getShared('dispatcher'); - $console->setArgument(array( - 'php', - 'main', - 'hello', - 'World', - '!' - ), false); + // testing namespace + $dispatcher->setDefaultNamespace('Dummy\\'); + + $console->setArgument( + [ + 'php', + 'main', + 'hello', + 'World', + '!', + ], + false + ); + $I->expectThrowable( + new DispatcherException( + 'Dummy\MainTask handler class cannot be loaded', + 2 + ), + function () use ($console) { $console->handle(); } ); @@ -318,29 +529,42 @@ function () { */ public function shouldThrowExceptionWithArguments(CliTester $I) { - $I->expectThrowable( - new DispatcherException('Dummy\MainTask handler class cannot be loaded', 2), + $this->container->setShared( + 'router', function () { - $this->container->setShared('router', function () { - $router = new Router(true); - return $router; - }); + $router = new Router(true); - $console = new Console(); - $console->setDI($this->container); - $dispatcher = $console->getDI()->getShared('dispatcher'); + return $router; + } + ); - // testing namespace - $dispatcher->setDefaultNamespace('Dummy\\'); + $console = new Console(); + + $console->setDI( + $this->container + ); - $console->setArgument(array( - 'php', - 'main', - 'hello', - 'World', - '!' - )); + $dispatcher = $console->getDI()->getShared('dispatcher'); + + // testing namespace + $dispatcher->setDefaultNamespace('Dummy\\'); + + $console->setArgument( + [ + 'php', + 'main', + 'hello', + 'World', + '!', + ] + ); + $I->expectThrowable( + new DispatcherException( + 'Dummy\MainTask handler class cannot be loaded', + 2 + ), + function () use ($console) { $console->handle(); } ); @@ -358,47 +582,129 @@ function () { ); $console = new Console(); + $console->setDI($this->container); + $dispatcher = $console->getDI()->getShared('dispatcher'); - $console->setArgument(array( - 'php' - ))->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'main'); - $I->assertEquals($dispatcher->getParams(), []); - $I->assertEquals($dispatcher->getReturnedValue(), 'mainAction'); - - $console->setArgument(array( - 'php', - 'echo' - ))->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'echo'); - $I->assertEquals($dispatcher->getActionName(), 'main'); - $I->assertEquals($dispatcher->getParams(), []); - $I->assertEquals($dispatcher->getReturnedValue(), 'echoMainAction'); - - $console->setArgument(array( - 'php', + + + $console->setArgument( + [ + 'php', + ] + )->handle(); + + $I->assertEquals( 'main', - 'hello' - ))->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'hello'); - $I->assertEquals($dispatcher->getParams(), []); - $I->assertEquals($dispatcher->getReturnedValue(), 'Hello !'); - - $console->setArgument(array( - 'php', + $dispatcher->getTaskName() + ); + + $I->assertEquals( 'main', + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'mainAction', + $dispatcher->getReturnedValue() + ); + + + + $console->setArgument( + [ + 'php', + 'echo', + ] + )->handle(); + + $I->assertEquals( + 'echo', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'main', + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'echoMainAction', + $dispatcher->getReturnedValue() + ); + + + + $console->setArgument( + [ + 'php', + 'main', + 'hello', + ] + )->handle(); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( 'hello', - 'World', - '######' - ))->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'hello'); - $I->assertEquals($dispatcher->getParams(), array('World', '######')); - $I->assertEquals($dispatcher->getReturnedValue(), 'Hello World######'); + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'Hello !', + $dispatcher->getReturnedValue() + ); + + + + $console->setArgument( + [ + 'php', + 'main', + 'hello', + 'World', + '######', + ] + )->handle(); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'hello', + $dispatcher->getActionName() + ); + + $I->assertEquals( + ['World', '######'], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'Hello World######', + $dispatcher->getReturnedValue() + ); } public function testArgumentOptions(CliTester $I) @@ -413,42 +719,112 @@ function () { ); $console = new Console(); - $console->setDI($this->container); + + $console->setDI( + $this->container + ); + $dispatcher = $console->getDI()->getShared('dispatcher'); - $console->setArgument(array( - 'php', - '-opt1', - '--option2', - '--option3=hoge', + + + $console->setArgument( + [ + 'php', + '-opt1', + '--option2', + '--option3=hoge', + 'main', + 'hello', + 'World', + '######', + ] + )->handle(); + + $I->assertEquals( 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( 'hello', - 'World', - '######' - ))->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'hello'); - $I->assertEquals($dispatcher->getParams(), array('World', '######')); - $I->assertEquals($dispatcher->getReturnedValue(), 'Hello World######'); - $I->assertEquals($dispatcher->getOptions(), array('opt1' => true, 'option2' => true, 'option3' => 'hoge')); - $I->assertTrue($dispatcher->hasOption('opt1')); - $I->assertFalse($dispatcher->hasOption('opt2')); - - $console->setArgument(array( - 'php', + $dispatcher->getActionName() + ); + + $I->assertEquals( + ['World', '######'], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'Hello World######', + $dispatcher->getReturnedValue() + ); + + $I->assertEquals( + [ + 'opt1' => true, + 'option2' => true, + 'option3' => 'hoge', + ], + $dispatcher->getOptions() + ); + + $I->assertTrue( + $dispatcher->hasOption('opt1') + ); + + $I->assertFalse( + $dispatcher->hasOption('opt2') + ); + + + + $console->setArgument( + [ + 'php', + 'main', + '-opt1', + 'hello', + '--option2', + 'World', + '--option3=hoge', + '######', + ] + )->handle(); + + $I->assertEquals( 'main', - '-opt1', + $dispatcher->getTaskName() + ); + + $I->assertEquals( 'hello', - '--option2', - 'World', - '--option3=hoge', - '######' - ))->handle(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'hello'); - $I->assertEquals($dispatcher->getParams(), array('World', '######')); - $I->assertEquals($dispatcher->getReturnedValue(), 'Hello World######'); - $I->assertEquals($dispatcher->getOptions(), array('opt1' => true, 'option2' => true, 'option3' => 'hoge')); - $I->assertEquals($dispatcher->getOption('option3'), 'hoge'); + $dispatcher->getActionName() + ); + + $I->assertEquals( + ['World', '######'], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'Hello World######', + $dispatcher->getReturnedValue() + ); + + $I->assertEquals( + [ + 'opt1' => true, + 'option2' => true, + 'option3' => 'hoge', + ], + $dispatcher->getOptions() + ); + + $I->assertEquals( + 'hoge', + $dispatcher->getOption('option3') + ); } } diff --git a/tests/cli/Cli/DispatcherCest.php b/tests/cli/Cli/DispatcherCest.php index bad3efe4399..c1a20e2fbb7 100644 --- a/tests/cli/Cli/DispatcherCest.php +++ b/tests/cli/Cli/DispatcherCest.php @@ -42,56 +42,179 @@ function () { ); $dispatcher = new Dispatcher(); - $dispatcher->setDI($this->container); + + $dispatcher->setDI( + $this->container + ); + + + $dispatcher->dispatch(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'main'); - $I->assertEquals($dispatcher->getParams(), []); - $I->assertEquals($dispatcher->getReturnedValue(), 'mainAction'); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'main', + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'mainAction', + $dispatcher->getReturnedValue() + ); + + $dispatcher->setTaskName('echo'); + $dispatcher->dispatch(); - $I->assertEquals($dispatcher->getTaskName(), 'echo'); - $I->assertEquals($dispatcher->getActionName(), 'main'); - $I->assertEquals($dispatcher->getParams(), []); - $I->assertEquals($dispatcher->getReturnedValue(), 'echoMainAction'); + + $I->assertEquals( + 'echo', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'main', + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'echoMainAction', + $dispatcher->getReturnedValue() + ); + + $dispatcher->setTaskName('main'); $dispatcher->setActionName('hello'); + $dispatcher->dispatch(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'hello'); - $I->assertEquals($dispatcher->getParams(), []); - $I->assertEquals($dispatcher->getReturnedValue(), 'Hello !'); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'hello', + $dispatcher->getActionName() + ); + + $I->assertEquals( + [], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'Hello !', + $dispatcher->getReturnedValue() + ); + + $dispatcher->setActionName('hello'); - $dispatcher->setParams(array('World', '######')); + + $dispatcher->setParams( + ['World', '######'] + ); + $dispatcher->dispatch(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'hello'); - $I->assertEquals($dispatcher->getParams(), array('World', '######')); - $I->assertEquals($dispatcher->getReturnedValue(), 'Hello World######'); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'hello', + $dispatcher->getActionName() + ); + + $I->assertEquals( + array('World', '######'), + $dispatcher->getParams() + ); + + $I->assertEquals( + 'Hello World######', + $dispatcher->getReturnedValue() + ); + + $dispatcher->setActionName('hello'); - $dispatcher->setParams(array('hello' => 'World', 'goodbye' => 'Everybody')); + + $dispatcher->setParams( + [ + 'hello' => 'World', + 'goodbye' => 'Everybody', + ] + ); + $dispatcher->dispatch(); - $I->assertTrue($dispatcher->hasParam('hello')); - $I->assertTrue($dispatcher->hasParam('goodbye')); - $I->assertFalse($dispatcher->hasParam('salutations')); + + $I->assertTrue( + $dispatcher->hasParam('hello') + ); + + $I->assertTrue( + $dispatcher->hasParam('goodbye') + ); + + $I->assertFalse( + $dispatcher->hasParam('salutations') + ); // testing namespace try { $dispatcher->setDefaultNamespace('Dummy\\'); $dispatcher->setTaskName('main'); $dispatcher->setActionName('hello'); - $dispatcher->setParams(array('World')); + + $dispatcher->setParams( + ['World'] + ); + $dispatcher->dispatch(); - $I->assertEquals($dispatcher->getTaskName(), 'main'); - $I->assertEquals($dispatcher->getActionName(), 'hello'); - $I->assertEquals($dispatcher->getParams(), array('World')); - $I->assertEquals($dispatcher->getReturnedValue(), 'Hello World!'); + + $I->assertEquals( + 'main', + $dispatcher->getTaskName() + ); + + $I->assertEquals( + 'hello', + $dispatcher->getActionName() + ); + + $I->assertEquals( + ['World'], + $dispatcher->getParams() + ); + + $I->assertEquals( + 'Hello World!', + $dispatcher->getReturnedValue() + ); } catch (\Exception $e) { - $I->assertEquals($e->getMessage(), 'Dummy\MainTask handler class cannot be loaded'); + $I->assertEquals( + 'Dummy\MainTask handler class cannot be loaded', + $e->getMessage() + ); } } @@ -100,20 +223,39 @@ public function testCliParameters(CliTester $I) $dispatcher = new Dispatcher(); $this->container->setShared("dispatcher", $dispatcher); - $dispatcher->setDI($this->container); + + $dispatcher->setDI( + $this->container + ); // Test $this->dispatcher->getParams() $dispatcher->setTaskName('params'); $dispatcher->setActionName('params'); - $dispatcher->setParams(array('This', 'Is', 'An', 'Example')); + + $dispatcher->setParams( + ['This', 'Is', 'An', 'Example'] + ); + $dispatcher->dispatch(); - $I->assertEquals($dispatcher->getReturnedValue(), 'Action params are the same as $this->dispatcher->getParams()'); + + $I->assertEquals( + 'Action params are the same as $this->dispatcher->getParams()', + $dispatcher->getReturnedValue() + ); // Test $this->dispatcher->getParam() $dispatcher->setTaskName('params'); $dispatcher->setActionName('param'); - $dispatcher->setParams(array('This', 'Is', 'An', 'Example')); + + $dispatcher->setParams( + ['This', 'Is', 'An', 'Example'] + ); + $dispatcher->dispatch(); - $I->assertEquals($dispatcher->getReturnedValue(), '$param[0] is the same as $this->dispatcher->getParam(0)'); + + $I->assertEquals( + '$param[0] is the same as $this->dispatcher->getParam(0)', + $dispatcher->getReturnedValue() + ); } } diff --git a/tests/cli/Cli/Router/Route/GetDescriptionCest.php b/tests/cli/Cli/Router/Route/GetDescriptionCest.php index 0ed4adb732e..37a446f7070 100644 --- a/tests/cli/Cli/Router/Route/GetDescriptionCest.php +++ b/tests/cli/Cli/Router/Route/GetDescriptionCest.php @@ -29,12 +29,16 @@ public function cliRouterRouteGetDescription(CliTester $I) $routes = $this->getExampleRoutes(); $router = new \Phalcon\Cli\Router(false); + foreach ($routes as $pattern => $description) { $router->add($pattern)->setDescription($description); } foreach ($router->getRoutes() as $route) { - $I->assertEquals($routes[$route->getPattern()], $route->getDescription()); + $I->assertEquals( + $routes[$route->getPattern()], + $route->getDescription() + ); } } diff --git a/tests/cli/Cli/Router/Route/SetDescriptionCest.php b/tests/cli/Cli/Router/Route/SetDescriptionCest.php index a11ea1de059..31b6511bab5 100644 --- a/tests/cli/Cli/Router/Route/SetDescriptionCest.php +++ b/tests/cli/Cli/Router/Route/SetDescriptionCest.php @@ -29,12 +29,16 @@ public function cliRouterRouteSetDescription(CliTester $I) $routes = $this->getExampleRoutes(); $router = new \Phalcon\Cli\Router(false); + foreach ($routes as $pattern => $description) { $router->add($pattern)->setDescription($description); } foreach ($router->getRoutes() as $route) { - $I->assertEquals($routes[$route->getPattern()], $route->getDescription()); + $I->assertEquals( + $routes[$route->getPattern()], + $route->getDescription() + ); } } diff --git a/tests/cli/Cli/RouterCest.php b/tests/cli/Cli/RouterCest.php index e475fd7ba26..6f79a6146d1 100644 --- a/tests/cli/Cli/RouterCest.php +++ b/tests/cli/Cli/RouterCest.php @@ -12,6 +12,7 @@ namespace Phalcon\Test\Cli\Cli; use CliTester; +use Codeception\Example; use Phalcon\Cli\Router; use Phalcon\Cli\Router\Route; use Phalcon\Test\Fixtures\Traits\DiTrait; @@ -33,40 +34,114 @@ function () { return "data"; } ); + $router = new Router(); - $router->handle([]); - $I->assertNull($router->getModuleName()); - $I->assertNull($router->getTaskName()); - $I->assertNull($router->getActionName()); - $I->assertEquals($router->getParams(), []); + + + + $router->handle( + [] + ); + + $I->assertNull( + $router->getModuleName() + ); + + $I->assertNull( + $router->getTaskName() + ); + + $I->assertNull( + $router->getActionName() + ); + + $I->assertEquals( + [], + $router->getParams() + ); + + + $router->handle( [ "task" => "main", ] ); - $I->assertNull($router->getModuleName()); - $I->assertEquals($router->getTaskName(), "main"); - $I->assertNull($router->getActionName()); - $I->assertEquals($router->getParams(), []); + + $I->assertNull( + $router->getModuleName() + ); + + $I->assertEquals( + "main", + $router->getTaskName() + ); + + $I->assertNull( + $router->getActionName() + ); + + $I->assertEquals( + [], + $router->getParams() + ); + + + $router->handle( [ "task" => "echo", ] ); - $I->assertNull($router->getModuleName()); - $I->assertEquals($router->getTaskName(), "echo"); - $I->assertNull($router->getActionName()); - $I->assertEquals($router->getParams(), []); + + $I->assertNull( + $router->getModuleName() + ); + + $I->assertEquals( + "echo", + $router->getTaskName() + ); + + $I->assertNull( + $router->getActionName() + ); + + $I->assertEquals( + [], + $router->getParams() + ); + + + $router->handle( [ "task" => "main", "action" => "hello", ] ); - $I->assertNull($router->getModuleName()); - $I->assertEquals($router->getTaskName(), "main"); - $I->assertEquals($router->getActionName(), "hello"); - $I->assertEquals($router->getParams(), []); + + $I->assertNull( + $router->getModuleName() + ); + + $I->assertEquals( + "main", + $router->getTaskName() + ); + + $I->assertEquals( + $router->getActionName(), + "hello" + ); + + $I->assertEquals( + [], + $router->getParams() + ); + + + $router->handle( [ "task" => "main", @@ -75,10 +150,28 @@ function () { "arg2", ] ); - $I->assertNull($router->getModuleName()); - $I->assertEquals($router->getTaskName(), "main"); - $I->assertEquals($router->getActionName(), "hello"); - $I->assertEquals($router->getParams(), ["arg1", "arg2"]); + + $I->assertNull( + $router->getModuleName() + ); + + $I->assertEquals( + "main", + $router->getTaskName() + ); + + $I->assertEquals( + "hello", + $router->getActionName() + ); + + $I->assertEquals( + ["arg1", "arg2"], + $router->getParams() + ); + + + $router->handle( [ "module" => "devtools", @@ -88,10 +181,29 @@ function () { "arg2", ] ); - $I->assertEquals($router->getModuleName(), "devtools"); - $I->assertEquals($router->getTaskName(), "main"); - $I->assertEquals($router->getActionName(), "hello"); - $I->assertEquals($router->getParams(), ["arg1", "arg2"]); + + $I->assertEquals( + "devtools", + $router->getModuleName() + ); + + $I->assertEquals( + "main", + $router->getTaskName() + ); + + $I->assertEquals( + "hello", + $router->getActionName() + ); + + $I->assertEquals( + ["arg1", "arg2"], + $router->getParams() + ); + + + $router->handle( [ "module" => "devtools", @@ -101,192 +213,330 @@ function () { "arg2", ] ); - $I->assertEquals($router->getModuleName(), "devtools"); - $I->assertEquals($router->getTaskName(), "echo"); - $I->assertEquals($router->getActionName(), "hello"); - $I->assertEquals($router->getParams(), ["arg1", "arg2"]); + + $I->assertEquals( + "devtools", + $router->getModuleName() + ); + + $I->assertEquals( + "echo", + $router->getTaskName() + ); + + $I->assertEquals( + "hello", + $router->getActionName() + ); + + $I->assertEquals( + ["arg1", "arg2"], + $router->getParams() + ); } - public function testRouter(CliTester $I) + /** + * @dataProvider getExamplesRouter + */ + public function testRouter(CliTester $I, Example $example) { - $examples = $this->getExamplesRouter(); - foreach ($examples as $example) { - $test = $example[0]; - Route::reset(); - $router = new Router(); - $router->add(' ', [ + Route::reset(); + + $router = new Router(); + + $router->add( + ' ', + [ 'module' => 'devtools', - 'task' => 'main', + 'task' => 'main', 'action' => 'hello', - ]); - $router->add('system :task a :action :params', [ - 'task' => 1, + ] + ); + + $router->add( + 'system :task a :action :params', + [ + 'task' => 1, 'action' => 2, 'params' => 3, - ]); - $router->add('([a-z]{2}) :task', [ - 'task' => 2, - 'action' => 'index', - 'language' => 1 - ]); - $router->add('admin :task :action :int', [ + ] + ); + + $router->add( + '([a-z]{2}) :task', + [ + 'task' => 2, + 'action' => 'index', + 'language' => 1, + ] + ); + + $router->add( + 'admin :task :action :int', + [ 'module' => 'admin', - 'task' => 1, + 'task' => 1, 'action' => 2, - 'id' => 3 - ]); - $router->add('posts ([0-9]{4}) ([0-9]{2}) ([0-9]{2}) :params', [ - 'task' => 'posts', + 'id' => 3, + ] + ); + + $router->add( + 'posts ([0-9]{4}) ([0-9]{2}) ([0-9]{2}) :params', + [ + 'task' => 'posts', 'action' => 'show', - 'year' => 1, - 'month' => 2, - 'day' => 3, + 'year' => 1, + 'month' => 2, + 'day' => 3, 'params' => 4, - ]); - $router->add('manual ([a-z]{2}) ([a-z\.]+)\.txt', [ - 'task' => 'manual', - 'action' => 'show', + ] + ); + + $router->add( + 'manual ([a-z]{2}) ([a-z\.]+)\.txt', + [ + 'task' => 'manual', + 'action' => 'show', 'language' => 1, - 'file' => 2 - ]); - $router->add('named-manual {language:([a-z]{2})} {file:[a-z\.]+}\.txt', [ - 'task' => 'manual', + 'file' => 2, + ] + ); + + $router->add( + 'named-manual {language:([a-z]{2})} {file:[a-z\.]+}\.txt', + [ + 'task' => 'manual', 'action' => 'show', - ]); - $router->add('very static route', [ - 'task' => 'static', - 'action' => 'route' - ]); - $router->add("feed {lang:[a-z]+} blog {blog:[a-z\-]+}\.{type:[a-z\-]+}", "Feed::get"); - $router->add("posts {year:[0-9]+} s {title:[a-z\-]+}", "Posts::show"); - $router->add("posts delete {id}", "Posts::delete"); - $router->add("show {id:video([0-9]+)} {title:[a-z\-]+}", "Videos::show"); - $this->runTests($I, $router, $test); - } + ] + ); + + $router->add( + 'very static route', + [ + 'task' => 'static', + 'action' => 'route', + ] + ); + + $router->add( + "feed {lang:[a-z]+} blog {blog:[a-z\-]+}\.{type:[a-z\-]+}", + "Feed::get" + ); + + $router->add( + "posts {year:[0-9]+} s {title:[a-z\-]+}", + "Posts::show" + ); + + $router->add( + "posts delete {id}", + "Posts::delete" + ); + + $router->add( + "show {id:video([0-9]+)} {title:[a-z\-]+}", + "Videos::show" + ); + + $this->runTests($I, $router, $example); } - public function testRouterParams(CliTester $I) + /** + * @dataProvider getExamplesRouterParams + */ + public function testRouterParams(CliTester $I, Example $example) { - $examples = $this->getExamplesRouterParams(); - foreach ($examples as $example) { - $test = $example[0]; - $router = new Router(); - $router->add('some {name}'); - $router->add('some {name} {id:[0-9]+}'); - $router->add('some {name} {id:[0-9]+} {date}'); - $this->runTests($I, $router, $test); - } + $router = new Router(); + + $router->add('some {name}'); + $router->add('some {name} {id:[0-9]+}'); + $router->add('some {name} {id:[0-9]+} {date}'); + + $this->runTests($I, $router, $example); } public function testNamedRoutes(CliTester $I) { Route::reset(); + $router = new Router(false); + $usersFind = $router->add('api users find')->setName('usersFind'); $usersAdd = $router->add('api users add')->setName('usersAdd'); - $I->assertEquals($usersAdd, $router->getRouteByName('usersAdd')); - $I->assertEquals($usersAdd, $router->getRouteByName('usersAdd')); - $I->assertEquals($usersFind, $router->getRouteById(0)); + + $I->assertEquals( + $usersAdd, + $router->getRouteByName('usersAdd') + ); + + $I->assertEquals( + $usersAdd, + $router->getRouteByName('usersAdd') + ); + + $I->assertEquals( + $usersFind, + $router->getRouteById(0) + ); } - public function testConverters(CliTester $I) + /** + * @dataProvider getExamplesConverters + */ + public function testConverters(CliTester $I, Example $example) { - $examples = $this->getExamplesConverters(); - foreach ($examples as $example) { - $route = $example['route']; - $paths = $example['paths']; - Route::reset(); - $router = new Router(); - $router - ->add('{task:[a-z\-]+} {action:[a-z\-]+} this-is-a-country') - ->convert( - 'task', - function ($task) { - return str_replace('-', '', $task); - } - ) - ->convert( - 'action', - function ($action) { - return str_replace('-', '', $action); - } - ); - - $router - ->add( - '([A-Z]+) ([0-9]+)', - [ - 'task' => 1, - 'action' => 'default', - 'id' => 2, - ] - ) - ->convert( - 'task', - function ($task) { - return strtolower($task); - } - ) - ->convert( - 'action', - function ($action) { - if ($action == 'default') { - return 'index'; - } - - return $action; - } - ) - ->convert( - 'id', - function ($id) { - return strrev($id); + $route = $example['route']; + $paths = $example['paths']; + + Route::reset(); + + $router = new Router(); + + $router + ->add('{task:[a-z\-]+} {action:[a-z\-]+} this-is-a-country') + ->convert( + 'task', + function ($task) { + return str_replace('-', '', $task); + } + ) + ->convert( + 'action', + function ($action) { + return str_replace('-', '', $action); + } + ); + + $router + ->add( + '([A-Z]+) ([0-9]+)', + [ + 'task' => 1, + 'action' => 'default', + 'id' => 2, + ] + ) + ->convert( + 'task', + function ($task) { + return strtolower($task); + } + ) + ->convert( + 'action', + function ($action) { + if ($action == 'default') { + return 'index'; } - ); - $router->handle($route); - $I->assertTrue($router->wasMatched()); - $I->assertEquals($paths['task'], $router->getTaskName()); - $I->assertEquals($paths['action'], $router->getActionName()); - } + + return $action; + } + ) + ->convert( + 'id', + function ($id) { + return strrev($id); + } + ); + + $router->handle($route); + + $I->assertTrue( + $router->wasMatched() + ); + + $I->assertEquals( + $paths['task'], + $router->getTaskName() + ); + + $I->assertEquals( + $paths['action'], + $router->getActionName() + ); } public function testShortPaths(CliTester $I) { Route::reset(); + $router = new Router(false); + + + $route = $router->add("route0", "Feed"); - $I->assertEquals($route->getPaths(), [ - 'task' => 'feed' - ]); + + $I->assertEquals( + [ + 'task' => 'feed', + ], + $route->getPaths() + ); + + + $route = $router->add("route1", "Feed::get"); - $I->assertEquals($route->getPaths(), [ - 'task' => 'feed', - 'action' => 'get', - ]); + + $I->assertEquals( + [ + 'task' => 'feed', + 'action' => 'get', + ], + $route->getPaths() + ); + + + $route = $router->add("route2", "News::Posts::show"); - $I->assertEquals($route->getPaths(), [ - 'module' => 'News', - 'task' => 'posts', - 'action' => 'show', - ]); + + $I->assertEquals( + [ + 'module' => 'News', + 'task' => 'posts', + 'action' => 'show', + ], + $route->getPaths() + ); + + + $route = $router->add("route3", "MyApp\\Tasks\\Posts::show"); - $I->assertEquals($route->getPaths(), [ - 'namespace' => 'MyApp\\Tasks', - 'task' => 'posts', - 'action' => 'show', - ]); + + $I->assertEquals( + [ + 'namespace' => 'MyApp\\Tasks', + 'task' => 'posts', + 'action' => 'show', + ], + $route->getPaths() + ); + + + $route = $router->add("route3", "News::MyApp\\Tasks\\Posts::show"); - $I->assertEquals($route->getPaths(), [ - 'module' => 'News', - 'namespace' => 'MyApp\\Tasks', - 'task' => 'posts', - 'action' => 'show', - ]); + + $I->assertEquals( + [ + 'module' => 'News', + 'namespace' => 'MyApp\\Tasks', + 'task' => 'posts', + 'action' => 'show', + ], + $route->getPaths() + ); + + + $route = $router->add("route3", "\\Posts::show"); - $I->assertEquals($route->getPaths(), [ - 'task' => 'posts', - 'action' => 'show', - ]); + + $I->assertEquals( + [ + 'task' => 'posts', + 'action' => 'show', + ], + $route->getPaths() + ); } public function testShortPaths2(CliTester $I) @@ -306,250 +556,322 @@ function () { public function testBeforeMatch(CliTester $I) { Route::reset(); + $trace = 0; + $router = new Router(false); + $router ->add('static route') - ->beforeMatch(function () use (&$trace) { - $trace++; - return false; - }); + ->beforeMatch( + function () use (&$trace) { + $trace++; + + return false; + } + ); + $router ->add('static route2') - ->beforeMatch(function () use (&$trace) { - $trace++; - return true; - }); + ->beforeMatch( + function () use (&$trace) { + $trace++; + + return true; + } + ); + + + $router->handle(); - $I->assertFalse($router->wasMatched()); + + $I->assertFalse( + $router->wasMatched() + ); + + + $router->handle('static route'); - $I->assertFalse($router->wasMatched()); + + $I->assertFalse( + $router->wasMatched() + ); + + + $router->handle('static route2'); - $I->assertTrue($router->wasMatched()); - $I->assertEquals($trace, 2); + + $I->assertTrue( + $router->wasMatched() + ); + + $I->assertEquals(2, $trace); } - public function testDelimiter(CliTester $I) + /** + * @dataProvider getExamplesDelimiter + */ + public function testDelimiter(CliTester $I, Example $example) { - $examples = $this->getExamplesDelimiter(); - foreach ($examples as $example) { - $test = $example[0]; - Route::reset(); - Route::delimiter('/'); - $router = new Router(); - $router->add('/', [ + Route::reset(); + Route::delimiter('/'); + + $router = new Router(); + + $router->add( + '/', + [ 'module' => 'devtools', - 'task' => 'main', + 'task' => 'main', 'action' => 'hello', - ]); - $router->add('/system/:task/a/:action/:params', [ - 'task' => 1, + ] + ); + + $router->add( + '/system/:task/a/:action/:params', + [ + 'task' => 1, 'action' => 2, 'params' => 3, - ]); - $router->add('/([a-z]{2})/:task', [ - 'task' => 2, - 'action' => 'index', - 'language' => 1 - ]); - $router->add('/admin/:task/:action/:int', [ + ] + ); + + $router->add( + '/([a-z]{2})/:task', + [ + 'task' => 2, + 'action' => 'index', + 'language' => 1, + ] + ); + + $router->add( + '/admin/:task/:action/:int', + [ 'module' => 'admin', - 'task' => 1, + 'task' => 1, 'action' => 2, - 'id' => 3 - ]); - $router->add('/posts/([0-9]{4})/([0-9]{2})/([0-9]{2})/:params', [ - 'task' => 'posts', + 'id' => 3, + ] + ); + + $router->add( + '/posts/([0-9]{4})/([0-9]{2})/([0-9]{2})/:params', + [ + 'task' => 'posts', 'action' => 'show', - 'year' => 1, - 'month' => 2, - 'day' => 3, + 'year' => 1, + 'month' => 2, + 'day' => 3, 'params' => 4, - ]); - $router->add('/manual/([a-z]{2})/([a-z\.]+)\.txt', [ - 'task' => 'manual', - 'action' => 'show', + ] + ); + + $router->add( + '/manual/([a-z]{2})/([a-z\.]+)\.txt', + [ + 'task' => 'manual', + 'action' => 'show', 'language' => 1, - 'file' => 2 - ]); - $router->add('/named-manual/{language:([a-z]{2})}/{file:[a-z\.]+}\.txt', [ - 'task' => 'manual', + 'file' => 2 + ] + ); + + $router->add( + '/named-manual/{language:([a-z]{2})}/{file:[a-z\.]+}\.txt', + [ + 'task' => 'manual', 'action' => 'show', - ]); - $router->add('/very/static/route', [ - 'task' => 'static', - 'action' => 'route' - ]); - $router->add("/feed/{lang:[a-z]+}/blog/{blog:[a-z\-]+}\.{type:[a-z\-]+}", "Feed::get"); - $router->add("/posts/{year:[0-9]+}/s/{title:[a-z\-]+}", "Posts::show"); - $router->add("/posts/delete/{id}", "Posts::delete"); - $router->add("/show/{id:video([0-9]+)}/{title:[a-z\-]+}", "Videos::show"); - - $this->runTests($I, $router, $test); - } + ] + ); + + $router->add( + '/very/static/route', + [ + 'task' => 'static', + 'action' => 'route', + ] + ); + + $router->add( + "/feed/{lang:[a-z]+}/blog/{blog:[a-z\-]+}\.{type:[a-z\-]+}", + "Feed::get" + ); + + $router->add( + "/posts/{year:[0-9]+}/s/{title:[a-z\-]+}", + "Posts::show" + ); + + $router->add( + "/posts/delete/{id}", + "Posts::delete" + ); + + $router->add( + "/show/{id:video([0-9]+)}/{title:[a-z\-]+}", + "Videos::show" + ); + + $this->runTests($I, $router, $example); } private function getExamplesRouter(): array { return [ [ - [ - 'uri' => '', - 'module' => null, - 'task' => null, - 'action' => null, - 'params' => [] - ] + 'uri' => '', + 'module' => null, + 'task' => null, + 'action' => null, + 'params' => [], ], + [ - [ - 'uri' => ' ', - 'module' => 'devtools', - 'task' => 'main', - 'action' => 'hello', - 'params' => [] - ] + 'uri' => ' ', + 'module' => 'devtools', + 'task' => 'main', + 'action' => 'hello', + 'params' => [], ], + [ - [ - 'uri' => 'documentation index hellao aaadpqñda bbbAdld cc-ccc', - 'module' => null, - 'task' => 'documentation', - 'action' => 'index', - 'params' => ['hellao', 'aaadpqñda', 'bbbAdld', 'cc-ccc'] - ] + 'uri' => 'documentation index hellao aaadpqñda bbbAdld cc-ccc', + 'module' => null, + 'task' => 'documentation', + 'action' => 'index', + 'params' => ['hellao', 'aaadpqñda', 'bbbAdld', 'cc-ccc'], ], + [ - [ - 'uri' => ' documentation index', - 'module' => null, - 'task' => 'documentation', - 'action' => 'index', - 'params' => [] - ] + 'uri' => ' documentation index', + 'module' => null, + 'task' => 'documentation', + 'action' => 'index', + 'params' => [], ], + [ - [ - 'uri' => 'documentation index ', - 'module' => null, - 'task' => 'documentation', - 'action' => 'index', - 'params' => [] - ] + 'uri' => 'documentation index ', + 'module' => null, + 'task' => 'documentation', + 'action' => 'index', + 'params' => [], ], + [ - [ - 'uri' => 'documentation index', - 'module' => null, - 'task' => 'documentation', - 'action' => 'index', - 'params' => [] - ] + 'uri' => 'documentation index', + 'module' => null, + 'task' => 'documentation', + 'action' => 'index', + 'params' => [], ], + [ - [ - 'uri' => 'documentation ', - 'module' => null, - 'task' => 'documentation', - 'action' => null, - 'params' => [] - ] + 'uri' => 'documentation ', + 'module' => null, + 'task' => 'documentation', + 'action' => null, + 'params' => [], ], + [ - [ - 'uri' => 'system admin a edit hellao aaadp', - 'module' => null, - 'task' => 'admin', - 'action' => 'edit', - 'params' => ['hellao', 'aaadp'] - ] + 'uri' => 'system admin a edit hellao aaadp', + 'module' => null, + 'task' => 'admin', + 'action' => 'edit', + 'params' => ['hellao', 'aaadp'], ], + [ - [ - 'uri' => 'es news', - 'module' => null, - 'task' => 'news', - 'action' => 'index', - 'params' => ['language' => 'es'] - ] + 'uri' => 'es news', + 'module' => null, + 'task' => 'news', + 'action' => 'index', + 'params' => ['language' => 'es'], ], + [ - [ - 'uri' => 'admin posts edit 100', - 'module' => 'admin', - 'task' => 'posts', - 'action' => 'edit', - 'params' => ['id' => 100] - ] + 'uri' => 'admin posts edit 100', + 'module' => 'admin', + 'task' => 'posts', + 'action' => 'edit', + 'params' => ['id' => 100], ], + [ - [ - 'uri' => 'posts 2010 02 10 title content', - 'module' => null, - 'task' => 'posts', - 'action' => 'show', - 'params' => [ - 'year' => '2010', - 'month' => '02', - 'day' => '10', - 0 => 'title', - 1 => 'content', - ] - ] + 'uri' => 'posts 2010 02 10 title content', + 'module' => null, + 'task' => 'posts', + 'action' => 'show', + 'params' => [ + 'year' => '2010', + 'month' => '02', + 'day' => '10', + 0 => 'title', + 1 => 'content', + ], ], + [ - [ - 'uri' => 'manual en translate.adapter.txt', - 'module' => null, - 'task' => 'manual', - 'action' => 'show', - 'params' => ['language' => 'en', 'file' => 'translate.adapter'] + 'uri' => 'manual en translate.adapter.txt', + 'module' => null, + 'task' => 'manual', + 'action' => 'show', + 'params' => [ + 'language' => 'en', + 'file' => 'translate.adapter', ] ], + [ - [ - 'uri' => 'named-manual en translate.adapter.txt', - 'module' => null, - 'task' => 'manual', - 'action' => 'show', - 'params' => ['language' => 'en', 'file' => 'translate.adapter'] + 'uri' => 'named-manual en translate.adapter.txt', + 'module' => null, + 'task' => 'manual', + 'action' => 'show', + 'params' => [ + 'language' => 'en', + 'file' => 'translate.adapter', ] ], + [ - [ - 'uri' => 'posts 1999 s le-nice-title', - 'module' => null, - 'task' => 'posts', - 'action' => 'show', - 'params' => ['year' => '1999', 'title' => 'le-nice-title'] - ] + 'uri' => 'posts 1999 s le-nice-title', + 'module' => null, + 'task' => 'posts', + 'action' => 'show', + 'params' => [ + 'year' => '1999', + 'title' => 'le-nice-title', + ], ], + [ - [ - 'uri' => 'feed fr blog diaporema.json', - 'module' => null, - 'task' => 'feed', - 'action' => 'get', - 'params' => ['lang' => 'fr', 'blog' => 'diaporema', 'type' => 'json'] - ] + 'uri' => 'feed fr blog diaporema.json', + 'module' => null, + 'task' => 'feed', + 'action' => 'get', + 'params' => [ + 'lang' => 'fr', + 'blog' => 'diaporema', + 'type' => 'json', + ], ], + [ - [ - 'uri' => 'posts delete 150', - 'module' => null, - 'task' => 'posts', - 'action' => 'delete', - 'params' => ['id' => '150'] - ] + 'uri' => 'posts delete 150', + 'module' => null, + 'task' => 'posts', + 'action' => 'delete', + 'params' => ['id' => '150'], ], + [ - [ - 'uri' => 'very static route', - 'module' => null, - 'task' => 'static', - 'action' => 'route', - 'params' => [] - ] + 'uri' => 'very static route', + 'module' => null, + 'task' => 'static', + 'action' => 'route', + 'params' => [], ], ]; } @@ -558,31 +880,36 @@ private function getExamplesRouterParams(): array { return [ [ - [ - 'uri' => 'some hattie', - 'module' => null, - 'task' => '', - 'action' => '', - 'params' => ['name' => 'hattie'] - ] + 'uri' => 'some hattie', + 'module' => null, + 'task' => '', + 'action' => '', + 'params' => [ + 'name' => 'hattie', + ], ], + [ - [ - 'uri' => 'some hattie 100', - 'module' => null, - 'task' => '', - 'action' => '', - 'params' => ['name' => 'hattie', 'id' => 100] - ] + 'uri' => 'some hattie 100', + 'module' => null, + 'task' => '', + 'action' => '', + 'params' => [ + 'name' => 'hattie', + 'id' => 100, + ], ], + [ - [ - 'uri' => 'some hattie 100 2011-01-02', - 'module' => null, - 'task' => '', - 'action' => '', - 'params' => ['name' => 'hattie', 'id' => 100, 'date' => '2011-01-02'] - ] + 'uri' => 'some hattie 100 2011-01-02', + 'module' => null, + 'task' => '', + 'action' => '', + 'params' => [ + 'name' => 'hattie', + 'id' => 100, + 'date' => '2011-01-02', + ], ], ]; } @@ -613,155 +940,155 @@ private function getExamplesDelimiter(): array { return [ [ - [ - 'uri' => '/', - 'module' => 'devtools', - 'task' => 'main', - 'action' => 'hello', - 'params' => [] - ] + 'uri' => '/', + 'module' => 'devtools', + 'task' => 'main', + 'action' => 'hello', + 'params' => [], ], + [ - [ - 'uri' => '/documentation/index/hellao/aaadpqñda/bbbAdld/cc-ccc', - 'module' => null, - 'task' => 'documentation', - 'action' => 'index', - 'params' => ['hellao', 'aaadpqñda', 'bbbAdld', 'cc-ccc'] - ] + 'uri' => '/documentation/index/hellao/aaadpqñda/bbbAdld/cc-ccc', + 'module' => null, + 'task' => 'documentation', + 'action' => 'index', + 'params' => ['hellao', 'aaadpqñda', 'bbbAdld', 'cc-ccc'], ], + [ - [ - 'uri' => '/documentation/index/', - 'module' => null, - 'task' => 'documentation', - 'action' => 'index', - 'params' => [] - ] + 'uri' => '/documentation/index/', + 'module' => null, + 'task' => 'documentation', + 'action' => 'index', + 'params' => [], ], + [ - [ - 'uri' => '/documentation/index', - 'module' => null, - 'task' => 'documentation', - 'action' => 'index', - 'params' => [] - ] + 'uri' => '/documentation/index', + 'module' => null, + 'task' => 'documentation', + 'action' => 'index', + 'params' => [], ], [ - [ - 'uri' => '/documentation/', - 'module' => null, - 'task' => 'documentation', - 'action' => null, - 'params' => [] - ] + 'uri' => '/documentation/', + 'module' => null, + 'task' => 'documentation', + 'action' => null, + 'params' => [], ], + [ - [ - 'uri' => '/system/admin/a/edit/hellao/aaadp', - 'module' => null, - 'task' => 'admin', - 'action' => 'edit', - 'params' => ['hellao', 'aaadp'] - ] + 'uri' => '/system/admin/a/edit/hellao/aaadp', + 'module' => null, + 'task' => 'admin', + 'action' => 'edit', + 'params' => ['hellao', 'aaadp'], ], + [ - [ - 'uri' => '/es/news', - 'module' => null, - 'task' => 'news', - 'action' => 'index', - 'params' => ['language' => 'es'] - ] + 'uri' => '/es/news', + 'module' => null, + 'task' => 'news', + 'action' => 'index', + 'params' => ['language' => 'es'], ], [ - [ - 'uri' => '/admin/posts/edit/100', - 'module' => 'admin', - 'task' => 'posts', - 'action' => 'edit', - 'params' => ['id' => 100] - ] + 'uri' => '/admin/posts/edit/100', + 'module' => 'admin', + 'task' => 'posts', + 'action' => 'edit', + 'params' => ['id' => 100], ], + [ - [ - 'uri' => '/posts/2010/02/10/title/content', - 'module' => null, - 'task' => 'posts', - 'action' => 'show', - 'params' => [ - 'year' => '2010', - 'month' => '02', - 'day' => '10', - 0 => 'title', - 1 => 'content', - ] - ] + 'uri' => '/posts/2010/02/10/title/content', + 'module' => null, + 'task' => 'posts', + 'action' => 'show', + 'params' => [ + 'year' => '2010', + 'month' => '02', + 'day' => '10', + 0 => 'title', + 1 => 'content', + ], ], + [ - [ - 'uri' => '/manual/en/translate.adapter.txt', - 'module' => null, - 'task' => 'manual', - 'action' => 'show', - 'params' => ['language' => 'en', 'file' => 'translate.adapter'] - ] + 'uri' => '/manual/en/translate.adapter.txt', + 'module' => null, + 'task' => 'manual', + 'action' => 'show', + 'params' => ['language' => 'en', 'file' => 'translate.adapter'], ], + [ - [ - 'uri' => '/named-manual/en/translate.adapter.txt', - 'module' => null, - 'task' => 'manual', - 'action' => 'show', - 'params' => ['language' => 'en', 'file' => 'translate.adapter'] - ] + 'uri' => '/named-manual/en/translate.adapter.txt', + 'module' => null, + 'task' => 'manual', + 'action' => 'show', + 'params' => ['language' => 'en', 'file' => 'translate.adapter'], ], + [ - [ - 'uri' => '/posts/1999/s/le-nice-title', - 'module' => null, - 'task' => 'posts', - 'action' => 'show', - 'params' => ['year' => '1999', 'title' => 'le-nice-title'] - ] + 'uri' => '/posts/1999/s/le-nice-title', + 'module' => null, + 'task' => 'posts', + 'action' => 'show', + 'params' => ['year' => '1999', 'title' => 'le-nice-title'], ], + [ - [ - 'uri' => '/feed/fr/blog/diaporema.json', - 'module' => null, - 'task' => 'feed', - 'action' => 'get', - 'params' => ['lang' => 'fr', 'blog' => 'diaporema', 'type' => 'json'] - ] + 'uri' => '/feed/fr/blog/diaporema.json', + 'module' => null, + 'task' => 'feed', + 'action' => 'get', + 'params' => ['lang' => 'fr', 'blog' => 'diaporema', 'type' => 'json'], ], + [ - [ - 'uri' => '/posts/delete/150', - 'module' => null, - 'task' => 'posts', - 'action' => 'delete', - 'params' => ['id' => '150'] - ] + 'uri' => '/posts/delete/150', + 'module' => null, + 'task' => 'posts', + 'action' => 'delete', + 'params' => ['id' => '150'], ], + [ - [ - 'uri' => '/very/static/route', - 'module' => null, - 'task' => 'static', - 'action' => 'route', - 'params' => [] - ] + 'uri' => '/very/static/route', + 'module' => null, + 'task' => 'static', + 'action' => 'route', + 'params' => [], ], ]; } - private function runTests(CliTester $I, $router, array $test) + private function runTests(CliTester $I, $router, Example $example) { - $router->handle($test['uri']); - $I->assertEquals($test['module'], $router->getModuleName()); - $I->assertEquals($test['task'], $router->getTaskName()); - $I->assertEquals($test['action'], $router->getActionName()); - $I->assertEquals($test['params'], $router->getParams()); + $router->handle( + $example['uri'] + ); + + $I->assertEquals( + $example['module'], + $router->getModuleName() + ); + + $I->assertEquals( + $example['task'], + $router->getTaskName() + ); + + $I->assertEquals( + $example['action'], + $router->getActionName() + ); + + $I->assertEquals( + $example['params'], + $router->getParams() + ); } } diff --git a/tests/cli/Cli/TaskCest.php b/tests/cli/Cli/TaskCest.php index 8cb6f7566a0..a4d9ddd1397 100644 --- a/tests/cli/Cli/TaskCest.php +++ b/tests/cli/Cli/TaskCest.php @@ -34,20 +34,42 @@ public function testTasks(CliTester $I) $this->container["registry"] = function () { $registry = new Registry(); + $registry->data = "data"; return $registry; }; $task = new \MainTask(); - $task->setDI($this->container); - $I->assertEquals($task->requestRegistryAction(), "data"); - $I->assertEquals($task->helloAction(), "Hello !"); - $I->assertEquals($task->helloAction("World"), "Hello World!"); + $task->setDI( + $this->container + ); + + $I->assertEquals( + "data", + $task->requestRegistryAction() + ); + + $I->assertEquals( + "Hello !", + $task->helloAction() + ); + + $I->assertEquals( + "Hello World!", + $task->helloAction("World") + ); $task2 = new \EchoTask(); - $task2->setDI($this->container); - $I->assertEquals($task2->mainAction(), "echoMainAction"); + + $task2->setDI( + $this->container + ); + + $I->assertEquals( + "echoMainAction", + $task2->mainAction() + ); } } diff --git a/tests/integration/Db/Adapter/Pdo/Factory/LoadCest.php b/tests/integration/Db/Adapter/Pdo/Factory/LoadCest.php index 8fc4743fc65..e0fba380888 100644 --- a/tests/integration/Db/Adapter/Pdo/Factory/LoadCest.php +++ b/tests/integration/Db/Adapter/Pdo/Factory/LoadCest.php @@ -44,8 +44,10 @@ public function _before(IntegrationTester $I) public function dbAdapterPdoFactoryLoadConfig(IntegrationTester $I) { $I->wantToTest("Db\Adapter\Pdo\Factory - load() - Config"); + $options = $this->config->database; $data = $options->toArray(); + $this->runTests($I, $options, $data); } @@ -59,13 +61,20 @@ private function runTests(IntegrationTester $I, $options, array $data) /** @var Mysql $database */ $database = Factory::load($options); - $class = Mysql::class; - $actual = $database; - $I->assertInstanceOf($class, $actual); + $I->assertInstanceOf( + Mysql::class, + $database + ); + + $expected = array_intersect_assoc( + $database->getDescriptor(), + $data + ); - $expected = array_intersect_assoc($database->getDescriptor(), $data); - $actual = $database->getDescriptor(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $database->getDescriptor() + ); } /** @@ -79,8 +88,10 @@ private function runTests(IntegrationTester $I, $options, array $data) public function dbAdapterPdoFactoryLoadArray(IntegrationTester $I) { $I->wantToTest("Db\Adapter\Pdo\Factory - load() - array"); + $options = $this->arrayConfig["database"]; $data = $options; + $this->runTests($I, $options, $data); } } diff --git a/tests/integration/Db/Adapter/Pdo/Mysql/DescribeColumnsCest.php b/tests/integration/Db/Adapter/Pdo/Mysql/DescribeColumnsCest.php index b09ca4ad4c8..c986bf22967 100644 --- a/tests/integration/Db/Adapter/Pdo/Mysql/DescribeColumnsCest.php +++ b/tests/integration/Db/Adapter/Pdo/Mysql/DescribeColumnsCest.php @@ -35,9 +35,21 @@ class DescribeColumnsCest public function dbAdapterPdoMysqlDescribeColumns(IntegrationTester $I) { $I->wantToTest("Db\Adapter\Pdo\Mysql - describeColumns()"); + $table = 'dialect_table'; $expected = $this->getExpectedColumns(); - $I->assertEquals($expected, $this->connection->describeColumns($table)); - $I->assertEquals($expected, $this->connection->describeColumns($table, $this->getSchemaName())); + + $I->assertEquals( + $expected, + $this->connection->describeColumns($table) + ); + + $I->assertEquals( + $expected, + $this->connection->describeColumns( + $table, + $this->getSchemaName() + ) + ); } } diff --git a/tests/integration/Db/Adapter/Pdo/Mysql/DescribeIndexesCest.php b/tests/integration/Db/Adapter/Pdo/Mysql/DescribeIndexesCest.php index 84e40e68ede..4731a143b4e 100644 --- a/tests/integration/Db/Adapter/Pdo/Mysql/DescribeIndexesCest.php +++ b/tests/integration/Db/Adapter/Pdo/Mysql/DescribeIndexesCest.php @@ -35,9 +35,21 @@ class DescribeIndexesCest public function dbAdapterPdoMysqlDescribeIndexes(IntegrationTester $I) { $I->wantToTest("Db\Adapter\Pdo\Mysql - describeIndexes()"); + $table = 'dialect_table'; $expected = $this->getExpectedIndexes(); - $I->assertEquals($expected, $this->connection->describeIndexes($table)); - $I->assertEquals($expected, $this->connection->describeIndexes($table, $this->getSchemaName())); + + $I->assertEquals( + $expected, + $this->connection->describeIndexes($table) + ); + + $I->assertEquals( + $expected, + $this->connection->describeIndexes( + $table, + $this->getSchemaName() + ) + ); } } diff --git a/tests/integration/Db/Adapter/Pdo/Mysql/DescribeReferencesCest.php b/tests/integration/Db/Adapter/Pdo/Mysql/DescribeReferencesCest.php index 032bd9cac38..11efb0a1f4a 100644 --- a/tests/integration/Db/Adapter/Pdo/Mysql/DescribeReferencesCest.php +++ b/tests/integration/Db/Adapter/Pdo/Mysql/DescribeReferencesCest.php @@ -35,10 +35,22 @@ class DescribeReferencesCest public function dbAdapterPdoMysqlDescribeReferences(IntegrationTester $I) { $I->wantToTest("Db\Adapter\Pdo\Mysql - describeReferences()"); + $table = 'dialect_table_intermediate'; $expected = $this->getExpectedReferences(); - $I->assertEquals($expected, $this->connection->describeReferences($table)); - $I->assertEquals($expected, $this->connection->describeReferences($table, $this->getSchemaName())); + + $I->assertEquals( + $expected, + $this->connection->describeReferences($table) + ); + + $I->assertEquals( + $expected, + $this->connection->describeReferences( + $table, + $this->getSchemaName() + ) + ); } /** @@ -52,16 +64,27 @@ public function dbAdapterPdoMysqlDescribeReferences(IntegrationTester $I) public function dbAdapterPdoMysqlDescribeReferencesCount(IntegrationTester $I) { $I->wantToTest("Db\Adapter\Pdo\Mysql - describeReferences() - count"); - $table = 'dialect_table_intermediate'; + + $table = 'dialect_table_intermediate'; + $directReferences = $this->connection->describeReferences($table); - $schemaReferences = $this->connection->describeReferences($table, $this->getSchemaName()); + + $schemaReferences = $this->connection->describeReferences( + $table, + $this->getSchemaName() + ); + $I->assertEquals($directReferences, $schemaReferences); - $I->assertEquals(2, count($directReferences)); - $I->assertEquals(2, count($schemaReferences)); + + $I->assertCount(2, $directReferences); + $I->assertCount(2, $schemaReferences); /** @var Reference $reference */ foreach ($directReferences as $reference) { - $I->assertEquals(1, count($reference->getColumns())); + $I->assertCount( + 1, + $reference->getColumns() + ); } } } diff --git a/tests/integration/Db/Adapter/Pdo/Mysql/TableExistsCest.php b/tests/integration/Db/Adapter/Pdo/Mysql/TableExistsCest.php index 9cf632a50dd..a474d4f1936 100644 --- a/tests/integration/Db/Adapter/Pdo/Mysql/TableExistsCest.php +++ b/tests/integration/Db/Adapter/Pdo/Mysql/TableExistsCest.php @@ -35,10 +35,26 @@ class TableExistsCest public function dbAdapterPdoMysqlTableExists(IntegrationTester $I) { $I->wantToTest('Db\Adapter\Pdo\Mysql - tableExists()'); + $table = 'dialect_table'; - $I->assertTrue($this->connection->tableExists($table)); - $I->assertFalse($this->connection->tableExists('unknown-table')); - $I->assertTrue($this->connection->tableExists($table, $this->getSchemaName())); - $I->assertFalse($this->connection->tableExists('unknown-table', 'unknown-db')); + + $I->assertTrue( + $this->connection->tableExists($table) + ); + + $I->assertFalse( + $this->connection->tableExists('unknown-table') + ); + + $I->assertTrue( + $this->connection->tableExists( + $table, + $this->getSchemaName() + ) + ); + + $I->assertFalse( + $this->connection->tableExists('unknown-table', 'unknown-db') + ); } } diff --git a/tests/integration/Db/Adapter/Pdo/Mysql/TableOptionsCest.php b/tests/integration/Db/Adapter/Pdo/Mysql/TableOptionsCest.php index ef59db91c65..aed887b560a 100644 --- a/tests/integration/Db/Adapter/Pdo/Mysql/TableOptionsCest.php +++ b/tests/integration/Db/Adapter/Pdo/Mysql/TableOptionsCest.php @@ -35,7 +35,7 @@ class TableOptionsCest public function dbAdapterPdoMysqlTableOptions(IntegrationTester $I) { $I->wantToTest('Db\Adapter\Pdo\Mysql - tableOptions()'); - $table = 'dialect_table'; + $expected = [ 'auto_increment' => '1', 'engine' => 'InnoDB', @@ -43,7 +43,11 @@ public function dbAdapterPdoMysqlTableOptions(IntegrationTester $I) 'table_type' => 'BASE TABLE', ]; - $actual = $this->connection->tableOptions($table, $this->getDatabaseName()); + $actual = $this->connection->tableOptions( + 'dialect_table', + $this->getDatabaseName() + ); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Db/Adapter/Pdo/MysqlCest.php b/tests/integration/Db/Adapter/Pdo/MysqlCest.php index ae7eccd2027..38a4e77289b 100644 --- a/tests/integration/Db/Adapter/Pdo/MysqlCest.php +++ b/tests/integration/Db/Adapter/Pdo/MysqlCest.php @@ -11,6 +11,7 @@ namespace Phalcon\Test\Integration\Db\Adapter\Pdo; +use Codeception\Example; use Helper\Dialect\MysqlTrait; use IntegrationTester; use Phalcon\Db\Adapter\Pdo\Mysql; @@ -41,7 +42,9 @@ public function _before(IntegrationTester $I) ] ); } catch (\PDOException $e) { - $I->skipTest("Unable to connect to the database: " . $e->getMessage()); + $I->skipTest( + "Unable to connect to the database: " . $e->getMessage() + ); } } @@ -90,11 +93,18 @@ public function testListTables(IntegrationTester $I) 'users', ]; - $actual = $this->connection->listTables(); - $I->assertEquals($expected, $actual); + + + $I->assertEquals( + $expected, + $this->connection->listTables() + ); + + $dbName = env('DATA_MYSQL_NAME', 'phalcon_test'); $actual = $this->connection->listTables($dbName); + $I->assertEquals($expected, $actual); } @@ -106,21 +116,30 @@ public function testListTables(IntegrationTester $I) */ public function testDescribeReferencesColumnsCount(IntegrationTester $I) { + $actual = $this->connection->describeReferences( + 'robots_parts', + env('DATA_MYSQL_NAME') + ); + + $I->assertCount(2, $actual); + + + + $I->assertCount( + 2, + $this->connection->describeReferences('robots_parts', null) + ); - $expected = 2; - $actual = $this->connection->describeReferences('robots_parts', env('DATA_MYSQL_NAME')); - $I->assertCount($expected, $actual); - $expected = 2; - $actual = $this->connection->describeReferences('robots_parts', null); - $I->assertCount($expected, $actual); $references = $actual; + /** @var Reference $reference */ foreach ($references as $reference) { - $expected = 1; - $actual = count($reference->getColumns()); - $I->assertEquals($expected, $actual); + $I->assertCount( + 1, + $reference->getColumns() + ); } } @@ -129,35 +148,43 @@ public function testDescribeReferencesColumnsCount(IntegrationTester $I) * * @author Sid Roberts * @since 2016-11-19 + * + * @dataProvider testEscapeIdentifierProvider */ - public function testEscapeIdentifier(IntegrationTester $I) + public function testEscapeIdentifier(IntegrationTester $I, Example $example) { - $examples = [ + $identifier = $example['identifier']; + $expected = $example['expected']; + + $I->assertEquals( + $expected, + $this->connection->escapeIdentifier($identifier) + ); + } + + private function testEscapeIdentifierProvider(): array + { + return [ [ "identifier" => "robots", "expected" => "`robots`", ], + [ "identifier" => ["schema", "robots"], "expected" => "`schema`.`robots`", ], + [ "identifier" => "`robots`", "expected" => "```robots```", ], + [ "identifier" => ["`schema`", "rob`ots"], "expected" => "```schema```.`rob``ots`", ], ]; - - foreach ($examples as $item) { - $identifier = $item['identifier']; - $expected = $item['expected']; - - $actual = $this->connection->escapeIdentifier($identifier); - $I->assertEquals($expected, $actual); - } } /** @@ -166,20 +193,32 @@ public function testEscapeIdentifier(IntegrationTester $I) * @issue https://github.com/phalcon/cphalcon/issues/556 * @author Sergii Svyrydenko * @since 2017-07-03 + * + * @dataProvider shouldAddForeignKeyProvider */ - public function shouldAddForeignKey(IntegrationTester $I) + public function shouldAddForeignKey(IntegrationTester $I, Example $example) { - $examples = [ - [$this->addForeignKeySql('test_name_key', 'CASCADE', 'RESTRICT'), true], - [$this->addForeignKeySql('', 'CASCADE', 'RESTRICT'), true], - ]; + $I->assertEquals( + $example['expected'], + $this->connection->execute( + $example['sql'] + ) + ); + } - foreach ($examples as $item) { - $sql = $item[0]; - $expected = $item[1]; - $actual = $this->connection->execute($sql); - $I->assertEquals($expected, $actual); - } + private function shouldAddForeignKeyProvider(): array + { + return [ + [ + 'sql' => $this->addForeignKeySql('test_name_key', 'CASCADE', 'RESTRICT'), + 'expected' => true, + ], + + [ + 'sql' => $this->addForeignKeySql('', 'CASCADE', 'RESTRICT'), + 'expected' => true, + ], + ]; } /** @@ -189,20 +228,37 @@ public function shouldAddForeignKey(IntegrationTester $I) * @issue https://github.com/phalcon/cphalcon/issues/556 * @author Sergii Svyrydenko * @since 2017-07-03 + * + * @dataProvider shouldCheckAddedForeignKeyProvider */ - public function shouldCheckAddedForeignKey(IntegrationTester $I) + public function shouldCheckAddedForeignKey(IntegrationTester $I, Example $example) { - $examples = [ - [$this->getForeignKeySql('test_name_key'), true], - [$this->getForeignKeySql('foreign_key_child_ibfk_1'), true], - ]; + $actual = $this->connection->execute( + $example['sql'], + [ + 'MYSQL_ATTR_USE_BUFFERED_QUERY', + ] + ); - foreach ($examples as $item) { - $sql = $item[0]; - $expected = $item[1]; - $actual = $this->connection->execute($sql, ['MYSQL_ATTR_USE_BUFFERED_QUERY']); - $I->assertEquals($expected, $actual); - } + $I->assertEquals( + $example['expected'], + $actual + ); + } + + private function shouldCheckAddedForeignKeyProvider(): array + { + return [ + [ + 'sql' => $this->getForeignKeySql('test_name_key'), + 'expected' => true, + ], + + [ + 'sql' => $this->getForeignKeySql('foreign_key_child_ibfk_1'), + 'expected' => true, + ], + ]; } /** @@ -212,19 +268,31 @@ public function shouldCheckAddedForeignKey(IntegrationTester $I) * @issue https://github.com/phalcon/cphalcon/issues/556 * @author Sergii Svyrydenko * @since 2017-07-03 + * + * @dataProvider shouldDropForeignKeyProvider */ - public function shouldDropForeignKey(IntegrationTester $I) + public function shouldDropForeignKey(IntegrationTester $I, Example $example) { - $examples = [ - [$this->dropForeignKeySql('test_name_key'), true], - [$this->dropForeignKeySql('foreign_key_child_ibfk_1'), true], - ]; + $I->assertEquals( + $example['expected'], + $this->connection->execute( + $example['sql'] + ) + ); + } - foreach ($examples as $item) { - $sql = $item[0]; - $expected = $item[1]; - $actual = $this->connection->execute($sql); - $I->assertEquals($expected, $actual); - } + private function shouldDropForeignKeyProvider(): array + { + return [ + [ + 'sql' => $this->dropForeignKeySql('test_name_key'), + 'expected' => true, + ], + + [ + 'sql' => $this->dropForeignKeySql('foreign_key_child_ibfk_1'), + 'expected' => true, + ], + ]; } } diff --git a/tests/integration/Db/Adapter/Pdo/Postgresql/DescribeColumnsCest.php b/tests/integration/Db/Adapter/Pdo/Postgresql/DescribeColumnsCest.php index 3c325d7758d..777c299bffc 100644 --- a/tests/integration/Db/Adapter/Pdo/Postgresql/DescribeColumnsCest.php +++ b/tests/integration/Db/Adapter/Pdo/Postgresql/DescribeColumnsCest.php @@ -38,6 +38,7 @@ class DescribeColumnsCest public function dbAdapterPdoPostgresqlDescribeColumns(IntegrationTester $I) { $I->wantToTest("Db\Adapter\Pdo\Postgresql - describeColumns()"); + $expected = [ Column::__set_state( [ @@ -81,10 +82,19 @@ public function dbAdapterPdoPostgresqlDescribeColumns(IntegrationTester $I) ), ]; + + $actual = $this->connection->describeColumns('images'); + $I->assertEquals($expected, $actual); - $actual = $this->connection->describeColumns('images', env('DATA_POSTGRES_SCHEMA')); + + + $actual = $this->connection->describeColumns( + 'images', + env('DATA_POSTGRES_SCHEMA') + ); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Db/Adapter/Pdo/Postgresql/DescribeReferencesCest.php b/tests/integration/Db/Adapter/Pdo/Postgresql/DescribeReferencesCest.php index b7a140d3005..9642a1f1ece 100644 --- a/tests/integration/Db/Adapter/Pdo/Postgresql/DescribeReferencesCest.php +++ b/tests/integration/Db/Adapter/Pdo/Postgresql/DescribeReferencesCest.php @@ -37,14 +37,21 @@ public function dbAdapterPdoPostgresqlDescribeReferences(IntegrationTester $I) $I->wantToTest("Db\Adapter\Pdo\Postgresql - describeReferences()"); $referencesNoSchema = $this->connection->describeReferences('robots_parts'); - $referencesSchema = $this->connection->describeReferences('robots_parts', env('DATA_POSTGRES_SCHEMA')); + + $referencesSchema = $this->connection->describeReferences( + 'robots_parts', + env('DATA_POSTGRES_SCHEMA') + ); $I->assertEquals($referencesNoSchema, $referencesSchema); $I->assertCount(2, $referencesNoSchema); foreach ($referencesNoSchema as $reference) { - $I->assertCount(1, $reference->getColumns()); + $I->assertCount( + 1, + $reference->getColumns() + ); } } } diff --git a/tests/integration/Db/Adapter/Pdo/Postgresql/TableExistsCest.php b/tests/integration/Db/Adapter/Pdo/Postgresql/TableExistsCest.php index 6660702d02e..cf384f0b066 100644 --- a/tests/integration/Db/Adapter/Pdo/Postgresql/TableExistsCest.php +++ b/tests/integration/Db/Adapter/Pdo/Postgresql/TableExistsCest.php @@ -37,9 +37,24 @@ public function dbAdapterPdoPostgresqlTableExists(IntegrationTester $I) $I->wantToTest("Db\Adapter\Pdo\Postgresql - tableExists()"); $table = 'dialect_table'; - $I->assertTrue($this->connection->tableExists($table)); - $I->assertFalse($this->connection->tableExists('unknown-table')); - $I->assertTrue($this->connection->tableExists($table, $this->getSchemaName())); - $I->assertFalse($this->connection->tableExists('unknown-table', 'unknown-db')); + + $I->assertTrue( + $this->connection->tableExists($table) + ); + + $I->assertFalse( + $this->connection->tableExists('unknown-table') + ); + + $I->assertTrue( + $this->connection->tableExists( + $table, + $this->getSchemaName() + ) + ); + + $I->assertFalse( + $this->connection->tableExists('unknown-table', 'unknown-db') + ); } } diff --git a/tests/integration/Db/Adapter/Pdo/PostgresqlCest.php b/tests/integration/Db/Adapter/Pdo/PostgresqlCest.php index 5df4a495836..2960f74c0bf 100644 --- a/tests/integration/Db/Adapter/Pdo/PostgresqlCest.php +++ b/tests/integration/Db/Adapter/Pdo/PostgresqlCest.php @@ -11,6 +11,7 @@ namespace Phalcon\Test\Integration\Db\Adapter\Pdo; +use Codeception\Example; use IntegrationTester; use Phalcon\Db\Dialect\Postgresql as DialectPostgresql; use Phalcon\Db\Reference; @@ -37,7 +38,8 @@ public function shouldCreateReferenceObject(IntegrationTester $I) { $expected = $this->getReferenceObject(); $connection = $this->getService('db'); - $actual = $connection->describeReferences('foreign_key_child', 'public'); + + $actual = $connection->describeReferences('foreign_key_child', 'public'); $I->assertEquals($expected, $actual); } @@ -64,42 +66,68 @@ private function getReferenceObject() * * @author Sergii Svyrydenko * @since 2017-07-05 + * + * @dataProvider shouldAddForeignKeyProvider */ - public function shouldAddForeignKey(IntegrationTester $I) + public function shouldAddForeignKey(IntegrationTester $I, Example $example) { - $examples = [ - ['fk1', true], - ['fk2', true], - ]; + $reference = $example['reference']; + + $dialect = new DialectPostgresql(); + + $references = $this->getReferenceAddForeignKey(); + + $sql = $dialect->addForeignKey( + 'foreign_key_child', + 'public', + $references[$reference] + ); - foreach ($examples as $item) { - $reference = $item[0]; - $expected = $item[1]; - $dialect = new DialectPostgresql(); - $references = $this->getReferenceAddForeignKey(); - $sql = $dialect->addForeignKey('foreign_key_child', 'public', $references[$reference]); - - $connection = $this->getService('db'); - $actual = $connection->execute($sql); - $I->assertEquals($expected, $actual); - } + $connection = $this->getService('db'); + $actual = $connection->execute($sql); + + $I->assertEquals( + $example['expected'], + $actual + ); + } + + private function shouldAddForeignKeyProvider(): array + { + return [ + [ + 'reference' => 'fk1', + 'expected' => true, + ], + + [ + 'reference' => 'fk2', + 'expected' => true, + ], + ]; } protected function getReferenceAddForeignKey() { return [ - 'fk1' => new Reference('fk1', [ - 'referencedTable' => 'foreign_key_parent', - 'columns' => ['child_int'], - 'referencedColumns' => ['refer_int'], - 'onDelete' => 'CASCADE', - 'onUpdate' => 'RESTRICT', - ]), - 'fk2' => new Reference('', [ - 'referencedTable' => 'foreign_key_parent', - 'columns' => ['child_int'], - 'referencedColumns' => ['refer_int'], - ]), + 'fk1' => new Reference( + 'fk1', + [ + 'referencedTable' => 'foreign_key_parent', + 'columns' => ['child_int'], + 'referencedColumns' => ['refer_int'], + 'onDelete' => 'CASCADE', + 'onUpdate' => 'RESTRICT', + ] + ), + 'fk2' => new Reference( + '', + [ + 'referencedTable' => 'foreign_key_parent', + 'columns' => ['child_int'], + 'referencedColumns' => ['refer_int'], + ] + ), ]; } @@ -108,28 +136,51 @@ protected function getReferenceAddForeignKey() * * @author Sergii Svyrydenko * @since 2017-07-05 + * + * @dataProvider shouldCheckAddedForeignKeyProvider */ - public function shouldCheckAddedForeignKey(IntegrationTester $I) + public function shouldCheckAddedForeignKey(IntegrationTester $I, Example $example) { - $examples = [ - [$this->getForeignKey('fk1'), 1], - [$this->getForeignKey('foreign_key_child_child_int_fkey'), 1], - ]; + $connection = $this->getService('db'); - foreach ($examples as $item) { - $sql = $item[0]; - $expected = $item[1]; + $actual = $connection->execute( + $example['sql'] + ); - $connection = $this->getService('db'); - $actual = $connection->execute($sql); - $I->assertEquals($expected, $actual); - } + $I->assertEquals( + $example['expected'], + $actual + ); + } + + private function shouldCheckAddedForeignKeyProvider(): array + { + return [ + [ + 'sql' => $this->getForeignKey('fk1'), + 'expected' => 1, + ], + + [ + 'sql' => $this->getForeignKey('foreign_key_child_child_int_fkey'), + 'expected' => 1, + ], + ]; } private function getForeignKey($foreignKeyName) { - $sql = rtrim(file_get_contents(dataFolder('fixtures/Db/postgresql/example9.sql'))); - str_replace('%_FK_%', $foreignKeyName, $sql); + $sql = rtrim( + file_get_contents( + dataFolder('fixtures/Db/postgresql/example9.sql') + ) + ); + + str_replace( + '%_FK_%', + $foreignKeyName, + $sql + ); return $sql; } @@ -140,23 +191,40 @@ private function getForeignKey($foreignKeyName) * @test * @author Sergii Svyrydenko * @since 2017-07-05 + * + * @dataProvider shouldDropForeignKeyProvider */ - public function shouldDropForeignKey(IntegrationTester $I) + public function shouldDropForeignKey(IntegrationTester $I, Example $example) { - $examples = [ - ['fk1', true], - ['foreign_key_child_child_int_fkey', true], - ]; + $dialect = new DialectPostgresql(); + + $sql = $dialect->dropForeignKey( + 'foreign_key_child', + 'public', + $example['reference'] + ); + + $connection = $this->getService('db'); + $actual = $connection->execute($sql); - foreach ($examples as $item) { - $reference = $item[0]; - $expected = $item[1]; - $dialect = new DialectPostgresql(); - $sql = $dialect->dropForeignKey('foreign_key_child', 'public', $reference); + $I->assertEquals( + $example['expected'], + $actual + ); + } - $connection = $this->getService('db'); - $actual = $connection->execute($sql); - $I->assertEquals($expected, $actual); - } + private function shouldDropForeignKeyProvider(): array + { + return [ + [ + 'reference' => 'fk1', + 'expected' => true, + ], + + [ + 'reference' => 'foreign_key_child_child_int_fkey', + 'expected' => true, + ], + ]; } } diff --git a/tests/integration/Db/Column/ConstantsCest.php b/tests/integration/Db/Column/ConstantsCest.php index 7b83bd7f3b3..9f4137e12ba 100644 --- a/tests/integration/Db/Column/ConstantsCest.php +++ b/tests/integration/Db/Column/ConstantsCest.php @@ -28,6 +28,7 @@ class ConstantsCest public function checkClassConstants(IntegrationTester $I) { $I->wantToTest("Db\Column :: constants"); + $I->assertEquals(3, Column::BIND_PARAM_BLOB); $I->assertEquals(5, Column::BIND_PARAM_BOOL); $I->assertEquals(32, Column::BIND_PARAM_DECIMAL); diff --git a/tests/integration/Db/Column/GetAfterPositionCest.php b/tests/integration/Db/Column/GetAfterPositionCest.php index 1fd78188504..2ab1defa110 100644 --- a/tests/integration/Db/Column/GetAfterPositionCest.php +++ b/tests/integration/Db/Column/GetAfterPositionCest.php @@ -35,10 +35,15 @@ class GetAfterPositionCest public function dbColumnGetAfterPosition(IntegrationTester $I) { $I->wantToTest("Db\Column - getAfterPosition()"); + $columns = $this->getColumns(); $expectedColumns = $this->getExpectedColumns(); + foreach ($expectedColumns as $index => $column) { - $I->assertEquals($columns[$index]['after'], $column->getAfterPosition()); + $I->assertEquals( + $columns[$index]['after'], + $column->getAfterPosition() + ); } } } diff --git a/tests/integration/Db/Column/GetBindTypeCest.php b/tests/integration/Db/Column/GetBindTypeCest.php index 62210ec4d02..5a33bd8d615 100644 --- a/tests/integration/Db/Column/GetBindTypeCest.php +++ b/tests/integration/Db/Column/GetBindTypeCest.php @@ -35,10 +35,15 @@ class GetBindTypeCest public function dbColumnGetBindType(IntegrationTester $I) { $I->wantToTest("Db\Column - getBindType()"); + $columns = $this->getColumns(); $expectedColumns = $this->getExpectedColumns(); + foreach ($expectedColumns as $index => $column) { - $I->assertEquals($columns[$index]['bindType'], $column->getBindType()); + $I->assertEquals( + $columns[$index]['bindType'], + $column->getBindType() + ); } } } diff --git a/tests/integration/Db/Column/GetDefaultCest.php b/tests/integration/Db/Column/GetDefaultCest.php index 89a9fb998dd..5e405cf9198 100644 --- a/tests/integration/Db/Column/GetDefaultCest.php +++ b/tests/integration/Db/Column/GetDefaultCest.php @@ -35,10 +35,15 @@ class GetDefaultCest public function dbColumnGetDefault(IntegrationTester $I) { $I->wantToTest("Db\Column - getDefault()"); + $columns = $this->getColumns(); $expectedColumns = $this->getExpectedColumns(); + foreach ($expectedColumns as $index => $column) { - $I->assertEquals($columns[$index]['default'], $column->getDefault()); + $I->assertEquals( + $columns[$index]['default'], + $column->getDefault() + ); } } } diff --git a/tests/integration/Db/Column/GetNameCest.php b/tests/integration/Db/Column/GetNameCest.php index 2a215e244e3..a12daeb7176 100644 --- a/tests/integration/Db/Column/GetNameCest.php +++ b/tests/integration/Db/Column/GetNameCest.php @@ -35,10 +35,15 @@ class GetNameCest public function dbColumnGetName(IntegrationTester $I) { $I->wantToTest("Db\Column - getName()"); + $columns = $this->getColumns(); $expectedColumns = $this->getExpectedColumns(); + foreach ($expectedColumns as $index => $column) { - $I->assertEquals($columns[$index]['columnName'], $column->getName()); + $I->assertEquals( + $columns[$index]['columnName'], + $column->getName() + ); } } } diff --git a/tests/integration/Db/Column/GetScaleCest.php b/tests/integration/Db/Column/GetScaleCest.php index c81e822ae2e..7222d5fcbc6 100644 --- a/tests/integration/Db/Column/GetScaleCest.php +++ b/tests/integration/Db/Column/GetScaleCest.php @@ -35,10 +35,15 @@ class GetScaleCest public function dbColumnGetScale(IntegrationTester $I) { $I->wantToTest("Db\Column - getScale()"); + $columns = $this->getColumns(); $expectedColumns = $this->getExpectedColumns(); + foreach ($expectedColumns as $index => $column) { - $I->assertEquals($columns[$index]['scale'], $column->getScale()); + $I->assertEquals( + $columns[$index]['scale'], + $column->getScale() + ); } } } diff --git a/tests/integration/Db/Column/GetSchemaNameCest.php b/tests/integration/Db/Column/GetSchemaNameCest.php index d133820c71e..ab722ccb66e 100644 --- a/tests/integration/Db/Column/GetSchemaNameCest.php +++ b/tests/integration/Db/Column/GetSchemaNameCest.php @@ -35,10 +35,15 @@ class GetSchemaNameCest public function dbColumnGetSchemaName(IntegrationTester $I) { $I->wantToTest("Db\Column - getSchemaName()"); + $columns = $this->getColumns(); $expectedColumns = $this->getExpectedColumns(); + foreach ($expectedColumns as $index => $column) { - $I->assertEquals($columns[$index]['schemaName'], $column->getSchemaName()); + $I->assertEquals( + $columns[$index]['schemaName'], + $column->getSchemaName() + ); } } } diff --git a/tests/integration/Db/Column/GetSizeCest.php b/tests/integration/Db/Column/GetSizeCest.php index e6593e4870f..0f30928e733 100644 --- a/tests/integration/Db/Column/GetSizeCest.php +++ b/tests/integration/Db/Column/GetSizeCest.php @@ -35,10 +35,15 @@ class GetSizeCest public function dbColumnGetSize(IntegrationTester $I) { $I->wantToTest("Db\Column - getSize()"); + $columns = $this->getColumns(); $expectedColumns = $this->getExpectedColumns(); + foreach ($expectedColumns as $index => $column) { - $I->assertEquals($columns[$index]['size'], $column->getSize()); + $I->assertEquals( + $columns[$index]['size'], + $column->getSize() + ); } } } diff --git a/tests/integration/Db/Column/GetTypeCest.php b/tests/integration/Db/Column/GetTypeCest.php index 1c1d9182b1a..fa405c4b271 100644 --- a/tests/integration/Db/Column/GetTypeCest.php +++ b/tests/integration/Db/Column/GetTypeCest.php @@ -35,10 +35,15 @@ class GetTypeCest public function dbColumnGetType(IntegrationTester $I) { $I->wantToTest("Db\Column - getType()"); + $columns = $this->getColumns(); $expectedColumns = $this->getExpectedColumns(); + foreach ($expectedColumns as $index => $column) { - $I->assertEquals($columns[$index]['type'], $column->getType()); + $I->assertEquals( + $columns[$index]['type'], + $column->getType() + ); } } } diff --git a/tests/integration/Db/Column/HasDefaultCest.php b/tests/integration/Db/Column/HasDefaultCest.php index 3891f8b3888..8af2f0adaf7 100644 --- a/tests/integration/Db/Column/HasDefaultCest.php +++ b/tests/integration/Db/Column/HasDefaultCest.php @@ -34,11 +34,21 @@ class HasDefaultCest */ public function dbColumnHasDefault(IntegrationTester $I, Example $data) { - $I->wantToTest(sprintf('Db\Column - hasDefault() - %s', $data['name'])); + $I->wantToTest( + sprintf( + 'Db\Column - hasDefault() - %s', + $data['name'] + ) + ); + $columns = $data['data']; $expected = $data['expected']; + foreach ($columns as $index => $column) { - $I->assertEquals($expected[$index], $column->hasDefault()); + $I->assertEquals( + $expected[$index], + $column->hasDefault() + ); } } diff --git a/tests/integration/Db/Column/IsAutoIncrementCest.php b/tests/integration/Db/Column/IsAutoIncrementCest.php index 285374fe13a..974aaca530d 100644 --- a/tests/integration/Db/Column/IsAutoIncrementCest.php +++ b/tests/integration/Db/Column/IsAutoIncrementCest.php @@ -34,11 +34,21 @@ class IsAutoIncrementCest */ public function dbColumnIsAutoIncrement(IntegrationTester $I, Example $data) { - $I->wantToTest(sprintf('Db\Column - isAutoIncrement() - %s', $data['name'])); + $I->wantToTest( + sprintf( + 'Db\Column - isAutoIncrement() - %s', + $data['name'] + ) + ); + $columns = $data['data']; $expected = $data['expected']; + foreach ($columns as $index => $column) { - $I->assertEquals($expected[$index], $column->isAutoIncrement()); + $I->assertEquals( + $expected[$index], + $column->isAutoIncrement() + ); } } diff --git a/tests/integration/Db/Column/IsFirstCest.php b/tests/integration/Db/Column/IsFirstCest.php index 4adc74a7e57..b56a78940c4 100644 --- a/tests/integration/Db/Column/IsFirstCest.php +++ b/tests/integration/Db/Column/IsFirstCest.php @@ -35,10 +35,15 @@ class IsFirstCest public function dbColumnIsFirst(IntegrationTester $I) { $I->wantToTest("Db\Column - isFirst()"); + $columns = $this->getColumns(); $expectedColumns = $this->getExpectedColumns(); + foreach ($expectedColumns as $index => $column) { - $I->assertEquals($columns[$index]['first'], $column->isFirst()); + $I->assertEquals( + $columns[$index]['first'], + $column->isFirst() + ); } } } diff --git a/tests/integration/Db/Column/IsNotNullCest.php b/tests/integration/Db/Column/IsNotNullCest.php index 7f707f1105d..bb0f2d59d85 100644 --- a/tests/integration/Db/Column/IsNotNullCest.php +++ b/tests/integration/Db/Column/IsNotNullCest.php @@ -35,10 +35,15 @@ class IsNotNullCest public function dbColumnIsNotNull(IntegrationTester $I) { $I->wantToTest("Db\Column - isNotNull()"); + $columns = $this->getColumns(); $expectedColumns = $this->getExpectedColumns(); + foreach ($expectedColumns as $index => $column) { - $I->assertEquals($columns[$index]['notNull'], $column->isNotNull()); + $I->assertEquals( + $columns[$index]['notNull'], + $column->isNotNull() + ); } } } diff --git a/tests/integration/Db/Column/IsNumericCest.php b/tests/integration/Db/Column/IsNumericCest.php index d2d11261a29..d06b03c8d0c 100644 --- a/tests/integration/Db/Column/IsNumericCest.php +++ b/tests/integration/Db/Column/IsNumericCest.php @@ -35,10 +35,15 @@ class IsNumericCest public function dbColumnIsNumeric(IntegrationTester $I) { $I->wantToTest("Db\Column - isNumeric()"); + $columns = $this->getColumns(); $expectedColumns = $this->getExpectedColumns(); + foreach ($expectedColumns as $index => $column) { - $I->assertEquals($columns[$index]['isNumeric'], $column->isNumeric()); + $I->assertEquals( + $columns[$index]['isNumeric'], + $column->isNumeric() + ); } } } diff --git a/tests/integration/Db/Column/IsPrimaryCest.php b/tests/integration/Db/Column/IsPrimaryCest.php index fda04d6ac54..d01ac8d68d3 100644 --- a/tests/integration/Db/Column/IsPrimaryCest.php +++ b/tests/integration/Db/Column/IsPrimaryCest.php @@ -35,10 +35,15 @@ class IsPrimaryCest public function dbColumnIsPrimary(IntegrationTester $I) { $I->wantToTest("Db\Column - isPrimary()"); + $columns = $this->getColumns(); $expectedColumns = $this->getExpectedColumns(); + foreach ($expectedColumns as $index => $column) { - $I->assertEquals($columns[$index]['primary'], $column->isPrimary()); + $I->assertEquals( + $columns[$index]['primary'], + $column->isPrimary() + ); } } } diff --git a/tests/integration/Db/Column/IsUnsignedCest.php b/tests/integration/Db/Column/IsUnsignedCest.php index e2c35f5f05b..ba6f2e7db54 100644 --- a/tests/integration/Db/Column/IsUnsignedCest.php +++ b/tests/integration/Db/Column/IsUnsignedCest.php @@ -35,10 +35,15 @@ class IsUnsignedCest public function dbColumnIsUnsigned(IntegrationTester $I) { $I->wantToTest("Db\Column - isUnsigned()"); + $columns = $this->getColumns(); $expectedColumns = $this->getExpectedColumns(); + foreach ($expectedColumns as $index => $column) { - $I->assertEquals($columns[$index]['unsigned'], $column->isUnsigned()); + $I->assertEquals( + $columns[$index]['unsigned'], + $column->isUnsigned() + ); } } } diff --git a/tests/integration/Db/DbBindCest.php b/tests/integration/Db/DbBindCest.php index d180095b97f..4bd3aa874b8 100644 --- a/tests/integration/Db/DbBindCest.php +++ b/tests/integration/Db/DbBindCest.php @@ -36,7 +36,9 @@ public function _before(IntegrationTester $I) public function dbBindMySql(IntegrationTester $I) { $I->wantToTest("Db - Bind - MySql"); + $this->setDiMysql(); + $connection = $this->getService('db'); $this->executeConvertBindTests($I, $connection); @@ -153,54 +155,75 @@ protected function executeBindByTypeTests(IntegrationTester $I, $connection) ["LOL 1", "A"], [Column::BIND_PARAM_STR, Column::BIND_PARAM_STR] ); + $I->assertTrue($success); + + $success = $connection->execute( 'UPDATE prueba SET nombre = ?, estado = ?', ["LOL 11", "R"], [Column::BIND_PARAM_STR, Column::BIND_PARAM_STR] ); + $I->assertTrue($success); + + $success = $connection->execute( 'DELETE FROM prueba WHERE estado = ?', ["R"], [Column::BIND_PARAM_STR] ); + $I->assertTrue($success); + + $success = $connection->insert( 'prueba', [$connection->getDefaultIdValue(), "LOL 1", "A"], null, [Column::BIND_SKIP, Column::BIND_PARAM_STR, Column::BIND_PARAM_STR] ); + $I->assertTrue($success); + + $success = $connection->insert( 'prueba', ["LOL 2", "E"], ['nombre', 'estado'], [Column::BIND_PARAM_STR, Column::BIND_PARAM_STR] ); + $I->assertTrue($success); + + $success = $connection->insert( 'prueba', ["LOL 3", "I"], ['nombre', 'estado'], [Column::BIND_PARAM_STR, Column::BIND_PARAM_STR] ); + $I->assertTrue($success); + + $success = $connection->insert( 'prueba', [new RawValue('current_date'), "A"], ['nombre', 'estado'], [Column::BIND_PARAM_STR, Column::BIND_PARAM_STR] ); + $I->assertTrue($success); + + $success = $connection->update( 'prueba', ["nombre", "estado"], @@ -208,8 +231,11 @@ protected function executeBindByTypeTests(IntegrationTester $I, $connection) "estado='E'", [Column::BIND_PARAM_STR, Column::BIND_PARAM_STR] ); + $I->assertTrue($success); + + $success = $connection->update( 'prueba', ["nombre"], @@ -217,8 +243,11 @@ protected function executeBindByTypeTests(IntegrationTester $I, $connection) "estado='X'", [Column::BIND_PARAM_STR] ); + $I->assertTrue($success); + + $success = $connection->update( 'prueba', ["nombre"], @@ -226,6 +255,7 @@ protected function executeBindByTypeTests(IntegrationTester $I, $connection) "estado='X'", [Column::BIND_PARAM_STR] ); + $I->assertTrue($success); } @@ -240,7 +270,9 @@ protected function executeBindByTypeTests(IntegrationTester $I, $connection) public function dbBindPostgresql(IntegrationTester $I) { $I->wantToTest("Db - Bind - Postgresql"); + $this->setDiMysql(); + $connection = $this->getService('db'); //$this->executeRawBindTests($I, $connection); @@ -259,7 +291,9 @@ public function dbBindPostgresql(IntegrationTester $I) public function dbBindSqlite(IntegrationTester $I) { $I->wantToTest("Db - Bind - Sqlite"); + $this->setDiSqlite(); + $connection = $this->getService('db'); //$this->_executeRawBindTests($connection); @@ -276,7 +310,11 @@ protected function executeRawBindTests(IntegrationTester $I, $connection) ] ); - $I->assertEquals($conditions, "a=100"); + $I->assertEquals( + "a=100", + $conditions + ); + $conditions = $connection->bindParams( @@ -287,7 +325,11 @@ protected function executeRawBindTests(IntegrationTester $I, $connection) ] ); - $I->assertEquals($conditions, "a=100"); + $I->assertEquals( + "a=100", + $conditions + ); + $conditions = $connection->bindParams( @@ -297,7 +339,11 @@ protected function executeRawBindTests(IntegrationTester $I, $connection) ] ); - $I->assertEquals($conditions, "a=?0"); + $I->assertEquals( + "a=?0", + $conditions + ); + $conditions = $connection->bindParams( @@ -308,7 +354,11 @@ protected function executeRawBindTests(IntegrationTester $I, $connection) ] ); - $I->assertEquals($conditions, "a=50 AND b = 25"); + $I->assertEquals( + "a=50 AND b = 25", + $conditions + ); + $conditions = $connection->bindParams( @@ -319,7 +369,11 @@ protected function executeRawBindTests(IntegrationTester $I, $connection) ] ); - $I->assertEquals($conditions, "a=50 AND b = 25"); + $I->assertEquals( + "a=50 AND b = 25", + $conditions + ); + $conditions = $connection->bindParams( @@ -330,7 +384,11 @@ protected function executeRawBindTests(IntegrationTester $I, $connection) ] ); - $I->assertEquals($conditions, "a=25.1 AND b = 25.10"); + $I->assertEquals( + "a=25.1 AND b = 25.10", + $conditions + ); + $conditions = $connection->bindParams( @@ -342,7 +400,11 @@ protected function executeRawBindTests(IntegrationTester $I, $connection) ] ); - $I->assertEquals($conditions, "a=50 AND b = 25 AND c<>15"); + $I->assertEquals( + "a=50 AND b = 25 AND c<>15", + $conditions + ); + $conditions = $connection->bindParams( @@ -352,7 +414,11 @@ protected function executeRawBindTests(IntegrationTester $I, $connection) ] ); - $I->assertEquals($conditions, "a='no-suprises'"); + $I->assertEquals( + "a='no-suprises'", + $conditions + ); + $conditions = $connection->bindParams( @@ -363,7 +429,10 @@ protected function executeRawBindTests(IntegrationTester $I, $connection) ] ); - $I->assertEquals($conditions, "column1 = 'hello' AND column2='lol'"); + $I->assertEquals( + "column1 = 'hello' AND column2='lol'", + $conditions + ); } protected function executeRawBindTestsMysql(IntegrationTester $I, $connection) @@ -377,7 +446,11 @@ protected function executeRawBindTestsMysql(IntegrationTester $I, $connection) ] ); - $I->assertEquals($conditions, "column3 IN ('hello', 100, '\'hahaha\'')"); + $I->assertEquals( + "column3 IN ('hello', 100, '\'hahaha\'')", + $conditions + ); + $conditions = $connection->bindParams( @@ -390,7 +463,10 @@ protected function executeRawBindTestsMysql(IntegrationTester $I, $connection) ] ); - $I->assertEquals($conditions, "column3 IN ('hello', 100, '\'hahaha\'') AND column4 > 'le-nice'"); + $I->assertEquals( + "column3 IN ('hello', 100, '\'hahaha\'') AND column4 > 'le-nice'", + $conditions + ); } protected function executeRawBindTestsPostgresql(IntegrationTester $I, $connection) @@ -404,7 +480,11 @@ protected function executeRawBindTestsPostgresql(IntegrationTester $I, $connecti ] ); - $I->assertEquals($conditions, "column3 IN ('hello', 100, '''hahaha''')"); + $I->assertEquals( + "column3 IN ('hello', 100, '''hahaha''')", + $conditions + ); + $conditions = $connection->bindParams( @@ -417,7 +497,10 @@ protected function executeRawBindTestsPostgresql(IntegrationTester $I, $connecti ] ); - $I->assertEquals($conditions, "column3 IN ('hello', 100, '''hahaha''') AND column4 > 'le-nice'"); + $I->assertEquals( + "column3 IN ('hello', 100, '''hahaha''') AND column4 > 'le-nice'", + $conditions + ); } protected function executeRawBindTestsSqlite(IntegrationTester $I, $connection) @@ -431,7 +514,11 @@ protected function executeRawBindTestsSqlite(IntegrationTester $I, $connection) ] ); - $I->assertEquals($conditions, "column3 IN ('hello', 100, '''hahaha''')"); + $I->assertEquals( + "column3 IN ('hello', 100, '''hahaha''')", + $conditions + ); + $conditions = $connection->bindParams( @@ -444,6 +531,9 @@ protected function executeRawBindTestsSqlite(IntegrationTester $I, $connection) ] ); - $I->assertEquals($conditions, "column3 IN ('hello', 100, '''hahaha''') AND column4 > 'le-nice'"); + $I->assertEquals( + "column3 IN ('hello', 100, '''hahaha''') AND column4 > 'le-nice'", + $conditions + ); } } diff --git a/tests/integration/Db/Dialect/Helper/DialectBase.php b/tests/integration/Db/Dialect/Helper/DialectBase.php index 4cf46eba696..d29118d666f 100644 --- a/tests/integration/Db/Dialect/Helper/DialectBase.php +++ b/tests/integration/Db/Dialect/Helper/DialectBase.php @@ -12,7 +12,6 @@ class DialectBase protected $adapter = 'Mysql'; - /** * Tests Dialect::createView * @@ -24,14 +23,24 @@ class DialectBase public function testCreateView(IntegrationTester $I) { $data = $this->getCreateViewFixtures(); + foreach ($data as $item) { $definition = $item[0]; $schema = $item[1]; $expected = $item[2]; - $dialect = $this->getDialectObject(); - $actual = $dialect->createView('test_view', $definition, $schema); - $I->assertTrue(is_string($actual)); + $dialect = $this->getDialectObject(); + + $actual = $dialect->createView( + 'test_view', + $definition, + $schema + ); + + $I->assertTrue( + is_string($actual) + ); + $I->assertEquals($expected, $actual); } } @@ -43,7 +52,10 @@ public function testCreateView(IntegrationTester $I) */ protected function getDialectObject(): DialectInterface { - $class = sprintf('Phalcon\Db\Dialect\%s', $this->adapter); + $class = sprintf( + 'Phalcon\Db\Dialect\%s', + $this->adapter + ); return new $class(); } @@ -61,12 +73,17 @@ protected function getDialectObject(): DialectInterface public function testDescribeColumns(IntegrationTester $I) { $data = $this->getDescribeColumnsFixtures(); + foreach ($data as $item) { $schema = $item[0]; $expected = $item[1]; $dialect = $this->getDialectObject(); - $actual = $dialect->describeColumns('table', $schema); + + $actual = $dialect->describeColumns( + 'table', + $schema + ); $I->assertEquals($expected, $actual); } @@ -91,12 +108,17 @@ public function testDescribeIndexes(IntegrationTester $I) public function testDescribeReferences(IntegrationTester $I) { $data = $this->getDescribeReferencesFixtures(); + foreach ($data as $item) { $schema = $item[0]; $expected = $item[1]; $dialect = $this->getDialectObject(); - $actual = $dialect->describeReferences('table', $schema); + + $actual = $dialect->describeReferences( + 'table', + $schema + ); $I->assertEquals($expected, $actual); } @@ -113,12 +135,19 @@ public function testDescribeReferences(IntegrationTester $I) public function testDropColumn(IntegrationTester $I) { $data = $this->getDropColumnFixtures(); + foreach ($data as $item) { $schema = $item[0]; $column = $item[1]; $expected = $item[2]; - $dialect = $this->getDialectObject(); - $actual = $dialect->dropColumn('table', $schema, $column); + + $dialect = $this->getDialectObject(); + + $actual = $dialect->dropColumn( + 'table', + $schema, + $column + ); $I->assertEquals($expected, $actual); } @@ -135,12 +164,19 @@ public function testDropColumn(IntegrationTester $I) public function testDropForeignKey(IntegrationTester $I) { $data = $this->getDropForeignKeyFixtures(); + foreach ($data as $item) { $schema = $item[0]; $key = $item[1]; $expected = $item[2]; + $dialect = $this->getDialectObject(); - $actual = $dialect->dropForeignKey('table', $schema, $key); + + $actual = $dialect->dropForeignKey( + 'table', + $schema, + $key + ); $I->assertEquals($expected, $actual); } @@ -157,12 +193,19 @@ public function testDropForeignKey(IntegrationTester $I) public function testDropIndex(IntegrationTester $I) { $data = $this->getDropIndexFixtures(); + foreach ($data as $item) { $schema = $item[0]; $index = $item[1]; $expected = $item[2]; - $dialect = $this->getDialectObject(); - $actual = $dialect->dropIndex('table', $schema, $index); + + $dialect = $this->getDialectObject(); + + $actual = $dialect->dropIndex( + 'table', + $schema, + $index + ); $I->assertEquals($expected, $actual); } @@ -179,11 +222,17 @@ public function testDropIndex(IntegrationTester $I) public function testDropPrimaryKey(IntegrationTester $I) { $data = $this->getDropPrimaryKeyFixtures(); + foreach ($data as $item) { $schema = $item[0]; $expected = $item[1]; - $dialect = $this->getDialectObject(); - $actual = $dialect->dropPrimaryKey('table', $schema); + + $dialect = $this->getDialectObject(); + + $actual = $dialect->dropPrimaryKey( + 'table', + $schema + ); $I->assertEquals($expected, $actual); } @@ -200,12 +249,19 @@ public function testDropPrimaryKey(IntegrationTester $I) public function testDropTable(IntegrationTester $I) { $data = $this->getDropTableFixtures(); + foreach ($data as $item) { $schema = $item[0]; $ifExists = $item[1]; $expected = $item[2]; - $dialect = $this->getDialectObject(); - $actual = $dialect->dropTable('table', $schema, $ifExists); + + $dialect = $this->getDialectObject(); + + $actual = $dialect->dropTable( + 'table', + $schema, + $ifExists + ); $I->assertEquals($expected, $actual); } @@ -222,14 +278,24 @@ public function testDropTable(IntegrationTester $I) public function testDropView(IntegrationTester $I) { $data = $this->getDropViewFixtures(); + foreach ($data as $item) { $schema = $item[0]; $ifExists = $item[1]; $expected = $item[2]; - $dialect = $this->getDialectObject(); - $actual = $dialect->dropView('test_view', $schema, $ifExists); - $I->assertTrue(is_string($actual)); + $dialect = $this->getDialectObject(); + + $actual = $dialect->dropView( + 'test_view', + $schema, + $ifExists + ); + + $I->assertTrue( + is_string($actual) + ); + $I->assertEquals($expected, $actual); } } @@ -253,12 +319,17 @@ public function testForUpdate(IntegrationTester $I) public function testGetColumnDefinition(IntegrationTester $I) { $data = $this->getColumnDefinitionFixtures(); + foreach ($data as $item) { $column = $item[0]; $expected = $item[1]; - $columns = $this->getColumns(); - $dialect = $this->getDialectObject(); - $actual = $dialect->getColumnDefinition($columns[$column]); + + $columns = $this->getColumns(); + $dialect = $this->getDialectObject(); + + $actual = $dialect->getColumnDefinition( + $columns[$column] + ); $I->assertEquals($expected, $actual); } @@ -275,13 +346,19 @@ public function testGetColumnDefinition(IntegrationTester $I) public function testGetColumnList(IntegrationTester $I) { $data = $this->getColumnListFixtures(); + foreach ($data as $item) { $columns = $item[0]; $expected = $item[1]; - $dialect = $this->getDialectObject(); - $actual = $dialect->getColumnList($columns); - $I->assertTrue(is_string($actual)); + $dialect = $this->getDialectObject(); + + $actual = $dialect->getColumnList($columns); + + $I->assertTrue( + is_string($actual) + ); + $I->assertEquals($expected, $actual); } } @@ -313,11 +390,14 @@ public function testListTables(IntegrationTester $I) public function testListViews(IntegrationTester $I) { $data = $this->getListViewFixtures(); + foreach ($data as $item) { $schema = $item[0]; $expected = $item[1]; - $dialect = $this->getDialectObject(); - $actual = $dialect->listViews($schema); + + $dialect = $this->getDialectObject(); + + $actual = $dialect->listViews($schema); $I->assertEquals($expected, $actual); } @@ -334,6 +414,7 @@ public function testListViews(IntegrationTester $I) public function testModifyColumn(IntegrationTester $I) { $data = $this->getModifyColumnFixtures(); + foreach ($data as $item) { $columns = $this->getColumns(); $schema = $item[0]; @@ -341,7 +422,13 @@ public function testModifyColumn(IntegrationTester $I) $from = $columns[$item[2]] ?? null; $expected = $item[3]; $dialect = $this->getDialectObject(); - $actual = $dialect->modifyColumn('table', $schema, $to, $from); + + $actual = $dialect->modifyColumn( + 'table', + $schema, + $to, + $from + ); $I->assertEquals($expected, $actual); } @@ -361,8 +448,18 @@ public function testModifyColumn13012(IntegrationTester $I) list($oldColumn, $newColumn) = $this->getModifyColumnFixtures13012(); $dialect = $this->getDialectObject(); + + + $expected = $this->getModifyColumnSql(); - $actual = $dialect->modifyColumn('table', 'database', $newColumn, $oldColumn); + + $actual = $dialect->modifyColumn( + 'table', + 'database', + $newColumn, + $oldColumn + ); + $I->assertEquals($expected, $actual); } @@ -376,9 +473,11 @@ public function testModifyColumn13012(IntegrationTester $I) */ public function testReleaseSavepoint(IntegrationTester $I) { - $dialect = $this->getDialectObject(); + $dialect = $this->getDialectObject(); + $expected = $this->getReleaseSavepointSql(); - $actual = $dialect->releaseSavepoint('PH_SAVEPOINT_1'); + + $actual = $dialect->releaseSavepoint('PH_SAVEPOINT_1'); $I->assertEquals($expected, $actual); } @@ -393,9 +492,11 @@ public function testReleaseSavepoint(IntegrationTester $I) */ public function testRollbackSavepoint(IntegrationTester $I) { - $dialect = $this->getDialectObject(); + $dialect = $this->getDialectObject(); + $expected = $this->getRollbackSavepointSql(); - $actual = $dialect->rollbackSavepoint('PH_SAVEPOINT_1'); + + $actual = $dialect->rollbackSavepoint('PH_SAVEPOINT_1'); $I->assertEquals($expected, $actual); } @@ -427,7 +528,8 @@ public function testSharedLock(IntegrationTester $I) public function testSupportsReleaseSavepoints(IntegrationTester $I) { $dialect = $this->getDialectObject(); - $actual = $dialect->supportsReleaseSavepoints(); + + $actual = $dialect->supportsReleaseSavepoints(); $I->assertTrue($actual); } @@ -443,7 +545,8 @@ public function testSupportsReleaseSavepoints(IntegrationTester $I) public function testSupportsSavepoints(IntegrationTester $I) { $dialect = $this->getDialectObject(); - $actual = $dialect->supportsSavepoints(); + + $actual = $dialect->supportsSavepoints(); $I->assertTrue($actual); } @@ -456,13 +559,22 @@ public function testSupportsSavepoints(IntegrationTester $I) public function testTableExists(IntegrationTester $I) { $data = $this->getTableExistsFixtures(); + foreach ($data as $item) { $schema = $item[0]; $expected = $item[1]; - $dialect = $this->getDialectObject(); - $actual = $dialect->tableExists('table', $schema); - $I->assertTrue(is_string($actual)); + $dialect = $this->getDialectObject(); + + $actual = $dialect->tableExists( + 'table', + $schema + ); + + $I->assertTrue( + is_string($actual) + ); + $I->assertEquals($expected, $actual); } } @@ -486,11 +598,16 @@ public function testTableOptions(IntegrationTester $I) public function testTruncateTable(IntegrationTester $I) { $data = $this->getTruncateTableFixtures(); + foreach ($data as $item) { $schema = $item[0]; $expected = $item[1]; $dialect = $this->getDialectObject(); - $actual = $dialect->truncateTable('table', $schema); + + $actual = $dialect->truncateTable( + 'table', + $schema + ); $I->assertEquals($expected, $actual); } @@ -507,13 +624,22 @@ public function testTruncateTable(IntegrationTester $I) public function testViewExists(IntegrationTester $I) { $data = $this->getViewExistsFixtures(); + foreach ($data as $item) { $schema = $item[0]; $expected = $item[1]; - $dialect = $this->getDialectObject(); - $actual = $dialect->viewExists('view', $schema); - $I->assertTrue(is_string($actual)); + $dialect = $this->getDialectObject(); + + $actual = $dialect->viewExists( + 'view', + $schema + ); + + $I->assertTrue( + is_string($actual) + ); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Db/Dialect/Helper/MysqlHelper.php b/tests/integration/Db/Dialect/Helper/MysqlHelper.php index b96040ad4f1..b1127881e25 100644 --- a/tests/integration/Db/Dialect/Helper/MysqlHelper.php +++ b/tests/integration/Db/Dialect/Helper/MysqlHelper.php @@ -19,14 +19,17 @@ class MysqlHelper protected function addForeignKeySql(string $foreignKeyName = '', string $onUpdate = '', string $onDelete = '') { $sql = 'ALTER TABLE `foreign_key_child` ADD'; + if ($foreignKeyName) { $sql .= ' CONSTRAINT `' . $foreignKeyName . '`'; } + $sql .= ' FOREIGN KEY (`child_int`) REFERENCES `foreign_key_parent`(`refer_int`)'; if ($onDelete) { $sql .= ' ON DELETE ' . $onDelete; } + if ($onUpdate) { $sql .= ' ON UPDATE ' . $onUpdate; } @@ -78,6 +81,7 @@ protected function getColumnListFixtures(): array ['column1', 'column2', 'column3'], '`column1`, `column2`, `column3`', ], + [ ['foo'], '`foo`', @@ -92,8 +96,21 @@ protected function getColumnListFixtures(): array protected function getCreateViewFixtures(): array { return [ - [['sql' => 'SELECT 1'], null, 'CREATE VIEW `test_view` AS SELECT 1'], - [['sql' => 'SELECT 1'], 'schema', 'CREATE VIEW `schema`.`test_view` AS SELECT 1'], + [ + [ + 'sql' => 'SELECT 1', + ], + null, + 'CREATE VIEW `test_view` AS SELECT 1', + ], + + [ + [ + 'sql' => 'SELECT 1', + ], + 'schema', + 'CREATE VIEW `schema`.`test_view` AS SELECT 1', + ], ]; } @@ -107,10 +124,12 @@ protected function getDescribeColumnsFixtures(): array 'schema.name.with.dots', 'DESCRIBE `schema.name.with.dots`.`table`', ], + [ null, 'DESCRIBE `table`', ], + [ 'schema', 'DESCRIBE `schema`.`table`', @@ -137,6 +156,7 @@ protected function getDescribeReferencesFixtures() "WHERE KCU.REFERENCED_TABLE_NAME IS NOT NULL AND " . "KCU.CONSTRAINT_SCHEMA = DATABASE() AND KCU.TABLE_NAME = 'table'", ], + [ 'schema', "SELECT DISTINCT KCU.TABLE_NAME, KCU.COLUMN_NAME, " . @@ -159,8 +179,17 @@ protected function getDescribeReferencesFixtures() protected function getDropColumnFixtures(): array { return [ - ['', 'column1', 'ALTER TABLE `table` DROP COLUMN `column1`'], - ['schema', 'column1', 'ALTER TABLE `schema`.`table` DROP COLUMN `column1`'], + [ + '', + 'column1', + 'ALTER TABLE `table` DROP COLUMN `column1`', + ], + + [ + 'schema', + 'column1', + 'ALTER TABLE `schema`.`table` DROP COLUMN `column1`', + ], ]; } @@ -170,8 +199,17 @@ protected function getDropColumnFixtures(): array protected function getDropForeignKeyFixtures(): array { return [ - ['', 'fk1', 'ALTER TABLE `table` DROP FOREIGN KEY `fk1`'], - ['schema', 'fk1', 'ALTER TABLE `schema`.`table` DROP FOREIGN KEY `fk1`'], + [ + '', + 'fk1', + 'ALTER TABLE `table` DROP FOREIGN KEY `fk1`', + ], + + [ + 'schema', + 'fk1', + 'ALTER TABLE `schema`.`table` DROP FOREIGN KEY `fk1`', + ], ]; } @@ -181,8 +219,17 @@ protected function getDropForeignKeyFixtures(): array protected function getDropIndexFixtures() { return [ - ['', 'index1', 'ALTER TABLE `table` DROP INDEX `index1`'], - ['schema', 'index1', 'ALTER TABLE `schema`.`table` DROP INDEX `index1`'], + [ + '', + 'index1', + 'ALTER TABLE `table` DROP INDEX `index1`', + ], + + [ + 'schema', + 'index1', + 'ALTER TABLE `schema`.`table` DROP INDEX `index1`', + ], ]; } @@ -192,8 +239,15 @@ protected function getDropIndexFixtures() protected function getDropPrimaryKeyFixtures(): array { return [ - ['', 'ALTER TABLE `table` DROP PRIMARY KEY'], - ['schema', 'ALTER TABLE `schema`.`table` DROP PRIMARY KEY'], + [ + '', + 'ALTER TABLE `table` DROP PRIMARY KEY', + ], + + [ + 'schema', + 'ALTER TABLE `schema`.`table` DROP PRIMARY KEY', + ], ]; } @@ -203,10 +257,29 @@ protected function getDropPrimaryKeyFixtures(): array protected function getDropTableFixtures(): array { return [ - ['', true, 'DROP TABLE IF EXISTS `table`'], - ['schema', true, 'DROP TABLE IF EXISTS `schema`.`table`'], - ['', false, 'DROP TABLE `table`'], - ['schema', false, 'DROP TABLE `schema`.`table`'], + [ + '', + true, + 'DROP TABLE IF EXISTS `table`', + ], + + [ + 'schema', + true, + 'DROP TABLE IF EXISTS `schema`.`table`', + ], + + [ + '', + false, + 'DROP TABLE `table`', + ], + + [ + 'schema', + false, + 'DROP TABLE `schema`.`table`', + ], ]; } @@ -216,10 +289,29 @@ protected function getDropTableFixtures(): array protected function getDropViewFixtures(): array { return [ - [null, false, 'DROP VIEW `test_view`'], - [null, true, 'DROP VIEW IF EXISTS `test_view`'], - ['schema', false, 'DROP VIEW `schema`.`test_view`'], - ['schema', true, 'DROP VIEW IF EXISTS `schema`.`test_view`'], + [ + null, + false, + 'DROP VIEW `test_view`', + ], + + [ + null, + true, + 'DROP VIEW IF EXISTS `test_view`', + ], + + [ + 'schema', + false, + 'DROP VIEW `schema`.`test_view`', + ], + + [ + 'schema', + true, + 'DROP VIEW IF EXISTS `schema`.`test_view`', + ], ]; } @@ -252,6 +344,7 @@ protected function getListViewFixtures(): array 'SELECT `TABLE_NAME` AS view_name FROM `INFORMATION_SCHEMA`.`VIEWS` ' . 'WHERE `TABLE_SCHEMA` = DATABASE() ORDER BY view_name', ], + [ 'schema', "SELECT `TABLE_NAME` AS view_name FROM `INFORMATION_SCHEMA`.`VIEWS` " . @@ -272,132 +365,154 @@ protected function getModifyColumnFixtures(): array null, 'ALTER TABLE `table` MODIFY `column1` VARCHAR(10)', ], + [ 'schema', 'column1', null, 'ALTER TABLE `schema`.`table` MODIFY `column1` VARCHAR(10)', ], + [ '', 'column2', null, 'ALTER TABLE `table` MODIFY `column2` INT(18) UNSIGNED', ], + [ 'schema', 'column2', null, 'ALTER TABLE `schema`.`table` MODIFY `column2` INT(18) UNSIGNED', ], + [ '', 'column3', null, 'ALTER TABLE `table` MODIFY `column3` DECIMAL(10,2) NOT NULL', ], + [ 'schema', 'column3', null, 'ALTER TABLE `schema`.`table` MODIFY `column3` DECIMAL(10,2) NOT NULL', ], + [ '', 'column4', null, 'ALTER TABLE `table` MODIFY `column4` CHAR(100) NOT NULL', ], + [ 'schema', 'column4', null, 'ALTER TABLE `schema`.`table` MODIFY `column4` CHAR(100) NOT NULL', ], + [ '', 'column5', null, 'ALTER TABLE `table` MODIFY `column5` DATE NOT NULL', ], + [ 'schema', 'column5', null, 'ALTER TABLE `schema`.`table` MODIFY `column5` DATE NOT NULL', ], + [ '', 'column6', null, 'ALTER TABLE `table` MODIFY `column6` DATETIME NOT NULL', ], + [ 'schema', 'column6', null, 'ALTER TABLE `schema`.`table` MODIFY `column6` DATETIME NOT NULL', ], + [ '', 'column7', null, 'ALTER TABLE `table` MODIFY `column7` TEXT NOT NULL', ], + [ 'schema', 'column7', null, 'ALTER TABLE `schema`.`table` MODIFY `column7` TEXT NOT NULL', ], + [ '', 'column8', null, 'ALTER TABLE `table` MODIFY `column8` FLOAT(10,2) NOT NULL', ], + [ 'schema', 'column8', null, 'ALTER TABLE `schema`.`table` MODIFY `column8` FLOAT(10,2) NOT NULL', ], + [ '', 'column9', null, 'ALTER TABLE `table` MODIFY `column9` VARCHAR(10) DEFAULT "column9"', ], + [ 'schema', 'column9', null, 'ALTER TABLE `schema`.`table` MODIFY `column9` VARCHAR(10) DEFAULT "column9"', ], + [ '', 'column10', null, 'ALTER TABLE `table` MODIFY `column10` INT(18) UNSIGNED DEFAULT "10"', ], + [ 'schema', 'column10', null, 'ALTER TABLE `schema`.`table` MODIFY `column10` INT(18) UNSIGNED DEFAULT "10"', ], + [ '', 'column11', null, 'ALTER TABLE `table` MODIFY `column11` BIGINT(20) UNSIGNED', ], + [ 'schema', 'column11', null, 'ALTER TABLE `schema`.`table` MODIFY `column11` BIGINT(20) UNSIGNED', ], + [ '', 'column12', @@ -405,6 +520,7 @@ protected function getModifyColumnFixtures(): array 'ALTER TABLE `table` MODIFY `column12` ENUM("A", "B", "C") ' . 'DEFAULT "A" NOT NULL AFTER `column11`', ], + [ 'schema', 'column12', @@ -412,6 +528,7 @@ protected function getModifyColumnFixtures(): array 'ALTER TABLE `schema`.`table` MODIFY `column12` ENUM("A", "B", "C") ' . 'DEFAULT "A" NOT NULL AFTER `column11`', ], + [ '', 'column13', @@ -419,6 +536,7 @@ protected function getModifyColumnFixtures(): array 'ALTER TABLE `table` MODIFY `column13` ' . 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL', ], + [ 'schema', 'column13', @@ -435,8 +553,18 @@ protected function getModifyColumnFixtures(): array protected function getModifyColumnFixtures13012(): array { return [ - new Column('old', ['type' => Column::TYPE_VARCHAR]), - new Column('new', ['type' => Column::TYPE_VARCHAR]), + new Column( + 'old', + [ + 'type' => Column::TYPE_VARCHAR, + ] + ), + new Column( + 'new', + [ + 'type' => Column::TYPE_VARCHAR, + ] + ), ]; } @@ -475,6 +603,7 @@ protected function getTableExistsFixtures(): array "SELECT IF(COUNT(*) > 0, 1, 0) FROM `INFORMATION_SCHEMA`.`TABLES` " . "WHERE `TABLE_NAME` = 'table' AND `TABLE_SCHEMA` = DATABASE()", ], + [ 'schema', "SELECT IF(COUNT(*) > 0, 1, 0) FROM `INFORMATION_SCHEMA`.`TABLES` " . @@ -489,8 +618,15 @@ protected function getTableExistsFixtures(): array protected function getTruncateTableFixtures(): array { return [ - ['', 'TRUNCATE TABLE `table`'], - ['schema', 'TRUNCATE TABLE `schema`.`table`'], + [ + '', + 'TRUNCATE TABLE `table`', + ], + + [ + 'schema', + 'TRUNCATE TABLE `schema`.`table`', + ], ]; } @@ -505,6 +641,7 @@ protected function getViewExistsFixtures(): array "SELECT IF(COUNT(*) > 0, 1, 0) FROM `INFORMATION_SCHEMA`.`VIEWS` " . "WHERE `TABLE_NAME`='view' AND `TABLE_SCHEMA` = DATABASE()", ], + [ 'schema', "SELECT IF(COUNT(*) > 0, 1, 0) FROM `INFORMATION_SCHEMA`.`VIEWS` " . diff --git a/tests/integration/Db/Dialect/Helper/SqliteHelper.php b/tests/integration/Db/Dialect/Helper/SqliteHelper.php index 6ae7037c614..b0b93a86621 100644 --- a/tests/integration/Db/Dialect/Helper/SqliteHelper.php +++ b/tests/integration/Db/Dialect/Helper/SqliteHelper.php @@ -85,8 +85,21 @@ protected function getColumnListFixtures(): array protected function getCreateViewFixtures(): array { return [ - [['sql' => 'SELECT 1'], null, 'CREATE VIEW "test_view" AS SELECT 1'], - [['sql' => 'SELECT 1'], 'schema', 'CREATE VIEW "schema"."test_view" AS SELECT 1'], + [ + [ + 'sql' => 'SELECT 1', + ], + null, + 'CREATE VIEW "test_view" AS SELECT 1', + ], + + [ + [ + 'sql' => 'SELECT 1', + ], + 'schema', + 'CREATE VIEW "schema"."test_view" AS SELECT 1', + ], ]; } @@ -199,8 +212,18 @@ protected function getModifyColumnFixtures(): array protected function getModifyColumnFixtures13012(): array { return [ - new Column('old', ['type' => Column::TYPE_VARCHAR]), - new Column('new', ['type' => Column::TYPE_VARCHAR]), + new Column( + 'old', + [ + 'type' => Column::TYPE_VARCHAR, + ] + ), + new Column( + 'new', + [ + 'type' => Column::TYPE_VARCHAR, + ] + ), ]; } diff --git a/tests/integration/Db/Dialect/PostgresqlCest.php b/tests/integration/Db/Dialect/PostgresqlCest.php index 74810571bbf..c7d9f5ea12c 100644 --- a/tests/integration/Db/Dialect/PostgresqlCest.php +++ b/tests/integration/Db/Dialect/PostgresqlCest.php @@ -237,14 +237,53 @@ protected function getAddForeignKeyFixtures(): array protected function getAddIndexFixtures() { return [ - ['', 'index1', 'CREATE INDEX "index1" ON "table" ("column1")'], - ['schema', 'index1', 'CREATE INDEX "index1" ON "schema"."table" ("column1")'], - ['', 'index2', 'CREATE INDEX "index2" ON "table" ("column1", "column2")'], - ['schema', 'index2', 'CREATE INDEX "index2" ON "schema"."table" ("column1", "column2")'], - ['', 'PRIMARY', 'ALTER TABLE "table" ADD CONSTRAINT "table_PRIMARY" PRIMARY KEY ("column3")'], - ['schema', 'PRIMARY', 'ALTER TABLE "schema"."table" ADD CONSTRAINT "table_PRIMARY" PRIMARY KEY ("column3")'], - ['', 'index4', 'CREATE UNIQUE INDEX "index4" ON "table" ("column4")'], - ['schema', 'index4', 'CREATE UNIQUE INDEX "index4" ON "schema"."table" ("column4")'], + [ + '', + 'index1', + 'CREATE INDEX "index1" ON "table" ("column1")', + ], + + [ + 'schema', + 'index1', + 'CREATE INDEX "index1" ON "schema"."table" ("column1")', + ], + + [ + '', + 'index2', + 'CREATE INDEX "index2" ON "table" ("column1", "column2")', + ], + + [ + 'schema', + 'index2', + 'CREATE INDEX "index2" ON "schema"."table" ("column1", "column2")', + ], + + [ + '', + 'PRIMARY', + 'ALTER TABLE "table" ADD CONSTRAINT "table_PRIMARY" PRIMARY KEY ("column3")', + ], + + [ + 'schema', + 'PRIMARY', + 'ALTER TABLE "schema"."table" ADD CONSTRAINT "table_PRIMARY" PRIMARY KEY ("column3")', + ], + + [ + '', + 'index4', + 'CREATE UNIQUE INDEX "index4" ON "table" ("column4")', + ], + + [ + 'schema', + 'index4', + 'CREATE UNIQUE INDEX "index4" ON "schema"."table" ("column4")', + ], ]; } @@ -254,8 +293,17 @@ protected function getAddIndexFixtures() protected function getAddPrimaryKeyFixtures(): array { return [ - ['', 'PRIMARY', 'ALTER TABLE "table" ADD CONSTRAINT "table_PRIMARY" PRIMARY KEY ("column3")'], - ['schema', 'PRIMARY', 'ALTER TABLE "schema"."table" ADD CONSTRAINT "table_PRIMARY" PRIMARY KEY ("column3")'], + [ + '', + 'PRIMARY', + 'ALTER TABLE "table" ADD CONSTRAINT "table_PRIMARY" PRIMARY KEY ("column3")', + ], + + [ + 'schema', + 'PRIMARY', + 'ALTER TABLE "schema"."table" ADD CONSTRAINT "table_PRIMARY" PRIMARY KEY ("column3")', + ], ]; } @@ -311,167 +359,254 @@ protected function getCreateTableFixtures(): array '', [ 'columns' => [ - new Column('column1', [ - 'type' => Column::TYPE_VARCHAR, - 'size' => 10, - ]), - new Column('column2', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 18, - 'unsigned' => true, - 'notNull' => false, - ]), + new Column( + 'column1', + [ + 'type' => Column::TYPE_VARCHAR, + 'size' => 10, + ] + ), + new Column( + 'column2', + [ + 'type' => Column::TYPE_INTEGER, + 'size' => 18, + 'unsigned' => true, + 'notNull' => false, + ] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/postgresql/example1.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/postgresql/example1.sql') + ) + ), ], 'example2' => [ '', [ 'columns' => [ - new Column('column2', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 18, - 'unsigned' => true, - 'notNull' => false, - ]), - new Column('column3', [ - 'type' => Column::TYPE_DECIMAL, - 'size' => 10, - 'scale' => 2, - 'unsigned' => false, - 'notNull' => true, - ]), - new Column('column1', [ - 'type' => Column::TYPE_VARCHAR, - 'size' => 10, - ]), + new Column( + 'column2', + [ + 'type' => Column::TYPE_INTEGER, + 'size' => 18, + 'unsigned' => true, + 'notNull' => false, + ] + ), + new Column( + 'column3', + [ + 'type' => Column::TYPE_DECIMAL, + 'size' => 10, + 'scale' => 2, + 'unsigned' => false, + 'notNull' => true, + ] + ), + new Column( + 'column1', + [ + 'type' => Column::TYPE_VARCHAR, + 'size' => 10, + ] + ), ], 'indexes' => [ - new Index('PRIMARY', ['column3']), + new Index( + 'PRIMARY', + ['column3'] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/postgresql/example2.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/postgresql/example2.sql') + ) + ), ], 'example3' => [ '', [ 'columns' => [ - new Column('column2', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 18, - 'unsigned' => true, - 'notNull' => false, - ]), - new Column('column3', [ - 'type' => Column::TYPE_DECIMAL, - 'size' => 10, - 'scale' => 2, - 'unsigned' => false, - 'notNull' => true, - ]), - new Column('column1', [ - 'type' => Column::TYPE_VARCHAR, - 'size' => 10, - ]), + new Column( + 'column2', + [ + 'type' => Column::TYPE_INTEGER, + 'size' => 18, + 'unsigned' => true, + 'notNull' => false, + ] + ), + new Column( + 'column3', + [ + 'type' => Column::TYPE_DECIMAL, + 'size' => 10, + 'scale' => 2, + 'unsigned' => false, + 'notNull' => true, + ] + ), + new Column( + 'column1', + [ + 'type' => Column::TYPE_VARCHAR, + 'size' => 10, + ] + ), ], 'indexes' => [ - new Index('PRIMARY', ['column3']), + new Index( + 'PRIMARY', + ['column3'] + ), ], 'references' => [ - new Reference('fk3', [ - 'referencedTable' => 'ref_table', - 'columns' => ['column1'], - 'referencedColumns' => ['column2'], - 'onDelete' => 'CASCADE', - ]), + new Reference( + 'fk3', + [ + 'referencedTable' => 'ref_table', + 'columns' => ['column1'], + 'referencedColumns' => ['column2'], + 'onDelete' => 'CASCADE', + ] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/postgresql/example3.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/postgresql/example3.sql') + ) + ), ], 'example4' => [ '', [ 'columns' => [ - new Column('column9', [ - 'type' => Column::TYPE_VARCHAR, - 'size' => 10, - 'default' => 'column9', - ]), - new Column('column10', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 18, - 'unsigned' => true, - 'notNull' => false, - 'default' => 10, - ]), + new Column( + 'column9', + [ + 'type' => Column::TYPE_VARCHAR, + 'size' => 10, + 'default' => 'column9', + ] + ), + new Column( + 'column10', + [ + 'type' => Column::TYPE_INTEGER, + 'size' => 18, + 'unsigned' => true, + 'notNull' => false, + 'default' => 10, + ] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/postgresql/example4.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/postgresql/example4.sql') + ) + ), ], 'example5' => [ '', [ 'columns' => [ - new Column('column11', [ - 'type' => 'BIGINT', - 'typeReference' => Column::TYPE_INTEGER, - 'size' => 20, - 'unsigned' => true, - 'notNull' => false, - ]), - new Column('column12', [ - 'type' => 'ENUM', - 'typeValues' => ['A', 'B', 'C'], - 'notNull' => true, - 'default' => 'A', - 'after' => 'column11', - ]), - new Column('column13', [ - 'type' => Column::TYPE_TIMESTAMP, - 'notNull' => true, - 'default' => 'CURRENT_TIMESTAMP', - ]), + new Column( + 'column11', + [ + 'type' => 'BIGINT', + 'typeReference' => Column::TYPE_INTEGER, + 'size' => 20, + 'unsigned' => true, + 'notNull' => false, + ] + ), + new Column( + 'column12', + [ + 'type' => 'ENUM', + 'typeValues' => ['A', 'B', 'C'], + 'notNull' => true, + 'default' => 'A', + 'after' => 'column11', + ] + ), + new Column( + 'column13', + [ + 'type' => Column::TYPE_TIMESTAMP, + 'notNull' => true, + 'default' => 'CURRENT_TIMESTAMP', + ] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/postgresql/example5.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/postgresql/example5.sql') + ) + ), ], 'example6' => [ '', [ 'columns' => [ - new Column('column14', [ - 'type' => Column::TYPE_INTEGER, - 'notNull' => true, - 'autoIncrement' => true, - 'first' => true, - ]), - new Column('column15', [ - 'type' => Column::TYPE_INTEGER, - 'default' => 5, - 'notNull' => true, - 'after' => 'user_id', - ]), - new Column('column16', [ - 'type' => Column::TYPE_VARCHAR, - 'size' => 10, - 'default' => 'column16', - ]), - new Column('column17', [ - 'type' => Column::TYPE_BOOLEAN, - 'default' => "false", - 'notNull' => true, - 'after' => 'track_id', - ]), - new Column('column18', [ - 'type' => Column::TYPE_BOOLEAN, - 'default' => "true", - 'notNull' => true, - 'after' => 'like', - ]), + new Column( + 'column14', + [ + 'type' => Column::TYPE_INTEGER, + 'notNull' => true, + 'autoIncrement' => true, + 'first' => true, + ] + ), + new Column( + 'column15', + [ + 'type' => Column::TYPE_INTEGER, + 'default' => 5, + 'notNull' => true, + 'after' => 'user_id', + ] + ), + new Column( + 'column16', + [ + 'type' => Column::TYPE_VARCHAR, + 'size' => 10, + 'default' => 'column16', + ] + ), + new Column( + 'column17', + [ + 'type' => Column::TYPE_BOOLEAN, + 'default' => "false", + 'notNull' => true, + 'after' => 'track_id', + ] + ), + new Column( + 'column18', + [ + 'type' => Column::TYPE_BOOLEAN, + 'default' => "true", + 'notNull' => true, + 'after' => 'like', + ] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/postgresql/example6.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/postgresql/example6.sql') + ) + ), ], ]; } @@ -490,8 +625,21 @@ protected function getCreateSavepointSql(): string protected function getCreateViewFixtures(): array { return [ - [['sql' => 'SELECT 1'], null, 'CREATE VIEW "test_view" AS SELECT 1'], - [['sql' => 'SELECT 1'], 'schema', 'CREATE VIEW "schema"."test_view" AS SELECT 1'], + [ + [ + 'sql' => 'SELECT 1', + ], + null, + 'CREATE VIEW "test_view" AS SELECT 1', + ], + + [ + [ + 'sql' => 'SELECT 1', + ], + 'schema', + 'CREATE VIEW "schema"."test_view" AS SELECT 1', + ], ]; } @@ -566,11 +714,20 @@ protected function getDescribeReferencesFixtures() return [ [ null, - rtrim(file_get_contents(dataFolder('fixtures/Db/postgresql/example7.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/postgresql/example7.sql') + ) + ), ], + [ 'schema', - rtrim(file_get_contents(dataFolder('fixtures/Db/postgresql/example8.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/postgresql/example8.sql') + ) + ), ], ]; } diff --git a/tests/integration/Db/Dialect/SqliteCest.php b/tests/integration/Db/Dialect/SqliteCest.php index 6b5456a35ab..492fd9e6469 100644 --- a/tests/integration/Db/Dialect/SqliteCest.php +++ b/tests/integration/Db/Dialect/SqliteCest.php @@ -251,10 +251,29 @@ protected function getAddForeignKeyFixtures(): array protected function getAddIndexFixtures() { return [ - ['', 'index1', 'CREATE INDEX "index1" ON "table" ("column1")'], - ['schema', 'index1', 'CREATE INDEX "schema"."index1" ON "table" ("column1")'], - ['', 'index2', 'CREATE INDEX "index2" ON "table" ("column1", "column2")'], - ['schema', 'index2', 'CREATE INDEX "schema"."index2" ON "table" ("column1", "column2")'], + [ + '', + 'index1', + 'CREATE INDEX "index1" ON "table" ("column1")', + ], + + [ + 'schema', + 'index1', + 'CREATE INDEX "schema"."index1" ON "table" ("column1")', + ], + + [ + '', + 'index2', + 'CREATE INDEX "index2" ON "table" ("column1", "column2")', + ], + + [ + 'schema', + 'index2', + 'CREATE INDEX "schema"."index2" ON "table" ("column1", "column2")', + ], ]; } @@ -320,165 +339,257 @@ protected function getCreateTableFixtures(): array '', [ 'columns' => [ - new Column('column1', [ - 'type' => Column::TYPE_VARCHAR, - 'size' => 10, - ]), - new Column('column2', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 18, - 'unsigned' => true, - 'notNull' => false, - ]), + new Column( + 'column1', + [ + 'type' => Column::TYPE_VARCHAR, + 'size' => 10, + ] + ), + new Column( + 'column2', + [ + 'type' => Column::TYPE_INTEGER, + 'size' => 18, + 'unsigned' => true, + 'notNull' => false, + ] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/sqlite/example1.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/sqlite/example1.sql') + ) + ), ], 'example2' => [ '', [ 'columns' => [ - new Column('column2', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 18, - 'unsigned' => true, - 'notNull' => false, - ]), - new Column('column3', [ - 'type' => Column::TYPE_DECIMAL, - 'size' => 10, - 'scale' => 2, - 'unsigned' => false, - 'notNull' => true, - ]), - new Column('column1', [ - 'type' => Column::TYPE_VARCHAR, - 'size' => 10, - ]), + new Column( + 'column2', + [ + 'type' => Column::TYPE_INTEGER, + 'size' => 18, + 'unsigned' => true, + 'notNull' => false, + ] + ), + new Column( + 'column3', + [ + 'type' => Column::TYPE_DECIMAL, + 'size' => 10, + 'scale' => 2, + 'unsigned' => false, + 'notNull' => true, + ] + ), + new Column( + 'column1', + [ + 'type' => Column::TYPE_VARCHAR, + 'size' => 10, + ] + ), ], 'indexes' => [ - new Index('PRIMARY', ['column3']), + new Index( + 'PRIMARY', + ['column3'] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/sqlite/example2.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/sqlite/example2.sql') + ) + ), ], 'example3' => [ '', [ 'columns' => [ - new Column('column2', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 18, - 'unsigned' => true, - 'notNull' => false, - ]), - new Column('column3', [ - 'type' => Column::TYPE_DECIMAL, - 'size' => 10, - 'scale' => 2, - 'unsigned' => false, - 'notNull' => true, - ]), - new Column('column1', [ - 'type' => Column::TYPE_VARCHAR, - 'size' => 10, - ]), + new Column( + 'column2', + [ + 'type' => Column::TYPE_INTEGER, + 'size' => 18, + 'unsigned' => true, + 'notNull' => false, + ] + ), + new Column( + 'column3', + [ + 'type' => Column::TYPE_DECIMAL, + 'size' => 10, + 'scale' => 2, + 'unsigned' => false, + 'notNull' => true, + ] + ), + new Column( + 'column1', + [ + 'type' => Column::TYPE_VARCHAR, + 'size' => 10, + ] + ), ], 'indexes' => [ - new Index('PRIMARY', ['column3']), + new Index( + 'PRIMARY', + ['column3'] + ), ], 'references' => [ - new Reference('fk3', [ - 'referencedTable' => 'ref_table', - 'columns' => ['column1'], - 'referencedColumns' => ['column2'], - 'onDelete' => 'CASCADE', - ]), + new Reference( + 'fk3', + [ + 'referencedTable' => 'ref_table', + 'columns' => ['column1'], + 'referencedColumns' => ['column2'], + 'onDelete' => 'CASCADE', + ] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/sqlite/example3.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/sqlite/example3.sql') + ) + ), ], 'example4' => [ '', [ 'columns' => [ - new Column('column9', [ - 'type' => Column::TYPE_VARCHAR, - 'size' => 10, - 'default' => 'column9', - ]), - new Column('column10', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 18, - 'unsigned' => true, - 'notNull' => false, - 'default' => 10, - ]), + new Column( + 'column9', + [ + 'type' => Column::TYPE_VARCHAR, + 'size' => 10, + 'default' => 'column9', + ] + ), + new Column( + 'column10', + [ + 'type' => Column::TYPE_INTEGER, + 'size' => 18, + 'unsigned' => true, + 'notNull' => false, + 'default' => 10, + ] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/sqlite/example4.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/sqlite/example4.sql') + ) + ), ], 'example5' => [ '', [ 'columns' => [ - new Column('column11', [ - 'type' => 'BIGINT', - 'typeReference' => Column::TYPE_INTEGER, - 'size' => 20, - 'unsigned' => true, - 'notNull' => false, - ]), - new Column('column13', [ - 'type' => Column::TYPE_TIMESTAMP, - 'notNull' => true, - 'default' => 'CURRENT_TIMESTAMP', - ]), + new Column( + 'column11', + [ + 'type' => 'BIGINT', + 'typeReference' => Column::TYPE_INTEGER, + 'size' => 20, + 'unsigned' => true, + 'notNull' => false, + ] + ), + new Column( + 'column13', + [ + 'type' => Column::TYPE_TIMESTAMP, + 'notNull' => true, + 'default' => 'CURRENT_TIMESTAMP', + ] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/sqlite/example5.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/sqlite/example5.sql') + ) + ), ], 'example6' => [ '', [ 'columns' => [ - new Column('column14', [ - 'type' => Column::TYPE_TINYBLOB, - 'notNull' => true, - ]), - new Column('column16', [ - 'type' => Column::TYPE_BLOB, - 'notNull' => true, - ]), + new Column( + 'column14', + [ + 'type' => Column::TYPE_TINYBLOB, + 'notNull' => true, + ] + ), + new Column( + 'column16', + [ + 'type' => Column::TYPE_BLOB, + 'notNull' => true, + ] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/sqlite/example6.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/sqlite/example6.sql') + ) + ), ], 'example7' => [ '', [ 'columns' => [ - new Column('column18', [ - 'type' => Column::TYPE_BOOLEAN, - ]), + new Column( + 'column18', + [ + 'type' => Column::TYPE_BOOLEAN, + ] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/sqlite/example7.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/sqlite/example7.sql') + ) + ), ], 'example8' => [ '', [ 'columns' => [ - new Column('column19', [ - 'type' => Column::TYPE_DOUBLE, - ]), - new Column('column20', [ - 'type' => Column::TYPE_DOUBLE, - 'unsigned' => true, - ]), + new Column( + 'column19', + [ + 'type' => Column::TYPE_DOUBLE, + ] + ), + new Column( + 'column20', + [ + 'type' => Column::TYPE_DOUBLE, + 'unsigned' => true, + ] + ), ], ], - rtrim(file_get_contents(dataFolder('fixtures/Db/sqlite/example8.sql'))), + rtrim( + file_get_contents( + dataFolder('fixtures/Db/sqlite/example8.sql') + ) + ), ], ]; } @@ -497,8 +608,21 @@ protected function getCreateSavepointSql(): string protected function getCreateViewFixtures(): array { return [ - [['sql' => 'SELECT 1'], null, 'CREATE VIEW "test_view" AS SELECT 1'], - [['sql' => 'SELECT 1'], 'schema', 'CREATE VIEW "schema"."test_view" AS SELECT 1'], + [ + [ + 'sql' => 'SELECT 1', + ], + null, + 'CREATE VIEW "test_view" AS SELECT 1', + ], + + [ + [ + 'sql' => 'SELECT 1', + ], + 'schema', + 'CREATE VIEW "schema"."test_view" AS SELECT 1', + ], ]; } @@ -508,9 +632,20 @@ protected function getCreateViewFixtures(): array protected function getDescribeColumnsFixtures(): array { return [ - ['schema.name.with.dots', "PRAGMA table_info('table')"], - ['', "PRAGMA table_info('table')"], - ['schema', "PRAGMA table_info('table')"], + [ + 'schema.name.with.dots', + "PRAGMA table_info('table')", + ], + + [ + '', + "PRAGMA table_info('table')", + ], + + [ + 'schema', + "PRAGMA table_info('table')", + ], ]; } @@ -520,8 +655,15 @@ protected function getDescribeColumnsFixtures(): array protected function getDescribeReferencesFixtures() { return [ - ['', "PRAGMA foreign_key_list('table')"], - ['schema', "PRAGMA foreign_key_list('table')"], + [ + '', + "PRAGMA foreign_key_list('table')", + ], + + [ + 'schema', + "PRAGMA foreign_key_list('table')", + ], ]; } @@ -547,8 +689,17 @@ protected function getDropForeignKeyFixtures(): array protected function getDropIndexFixtures() { return [ - ['', 'index1', 'DROP INDEX "index1"'], - ['schema', 'index1', 'DROP INDEX "schema"."index1"'], + [ + '', + 'index1', + 'DROP INDEX "index1"', + ], + + [ + 'schema', + 'index1', + 'DROP INDEX "schema"."index1"', + ], ]; } @@ -566,10 +717,29 @@ protected function getDropPrimaryKeyFixtures(): array protected function getDropTableFixtures(): array { return [ - ['', true, 'DROP TABLE IF EXISTS "table"'], - ['schema', true, 'DROP TABLE IF EXISTS "schema"."table"'], - ['', false, 'DROP TABLE "table"'], - ['schema', false, 'DROP TABLE "schema"."table"'], + [ + '', + true, + 'DROP TABLE IF EXISTS "table"', + ], + + [ + 'schema', + true, + 'DROP TABLE IF EXISTS "schema"."table"', + ], + + [ + '', + false, + 'DROP TABLE "table"', + ], + + [ + 'schema', + false, + 'DROP TABLE "schema"."table"', + ], ]; } @@ -579,10 +749,29 @@ protected function getDropTableFixtures(): array protected function getDropViewFixtures(): array { return [ - ['', false, 'DROP VIEW "test_view"'], - ['', true, 'DROP VIEW IF EXISTS "test_view"'], - ['schema', false, 'DROP VIEW "schema"."test_view"'], - ['schema', true, 'DROP VIEW IF EXISTS "schema"."test_view"'], + [ + '', + false, + 'DROP VIEW "test_view"', + ], + + [ + '', + true, + 'DROP VIEW IF EXISTS "test_view"', + ], + + [ + 'schema', + false, + 'DROP VIEW "schema"."test_view"', + ], + + [ + 'schema', + true, + 'DROP VIEW IF EXISTS "schema"."test_view"', + ], ]; } @@ -592,8 +781,15 @@ protected function getDropViewFixtures(): array protected function getListViewFixtures(): array { return [ - ['', "SELECT tbl_name FROM sqlite_master WHERE type = 'view' ORDER BY tbl_name"], - ['schema', "SELECT tbl_name FROM sqlite_master WHERE type = 'view' ORDER BY tbl_name"], + [ + '', + "SELECT tbl_name FROM sqlite_master WHERE type = 'view' ORDER BY tbl_name", + ], + + [ + 'schema', + "SELECT tbl_name FROM sqlite_master WHERE type = 'view' ORDER BY tbl_name", + ], ]; } @@ -611,8 +807,18 @@ protected function getModifyColumnFixtures(): array protected function getModifyColumnFixtures13012(): array { return [ - new Column('old', ['type' => Column::TYPE_VARCHAR]), - new Column('new', ['type' => Column::TYPE_VARCHAR]), + new Column( + 'old', + [ + 'type' => Column::TYPE_VARCHAR, + ] + ), + new Column( + 'new', + [ + 'type' => Column::TYPE_VARCHAR, + ] + ), ]; } @@ -654,8 +860,15 @@ protected function getTableExistsFixtures(): array protected function getTruncateTableFixtures(): array { return [ - ['', 'DELETE FROM "table"'], - ['schema', 'DELETE FROM "schema"."table"'], + [ + '', + 'DELETE FROM "table"', + ], + + [ + 'schema', + 'DELETE FROM "schema"."table"', + ], ]; } @@ -670,6 +883,7 @@ protected function getViewExistsFixtures(): array "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END " . "FROM sqlite_master WHERE type='view' AND tbl_name='view'", ], + [ 'schema', "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END " . diff --git a/tests/integration/Db/IndexCest.php b/tests/integration/Db/IndexCest.php index 934b5c7b131..b74920713ec 100644 --- a/tests/integration/Db/IndexCest.php +++ b/tests/integration/Db/IndexCest.php @@ -15,25 +15,81 @@ public function shouldWorkPerfectlyWithIndexAsObject(IntegrationTester $I) $indexes = $this->getIndexes(); $index1 = $indexes['index1']; - $I->assertEquals($index1->getName(), 'index1'); - $I->assertEquals($index1->getColumns(), ['column1']); + + $I->assertEquals( + 'index1', + $index1->getName() + ); + + $I->assertEquals( + ['column1'], + $index1->getColumns() + ); + + $index2 = $indexes['index2']; - $I->assertEquals($index2->getName(), 'index2'); - $I->assertEquals($index2->getColumns(), ['column1', 'column2']); + + $I->assertEquals( + 'index2', + $index2->getName() + ); + + $I->assertEquals( + ['column1', 'column2'], + $index2->getColumns() + ); + + $index3 = $indexes['PRIMARY']; - $I->assertEquals($index3->getName(), 'PRIMARY'); - $I->assertEquals($index3->getColumns(), ['column3']); + + $I->assertEquals( + 'PRIMARY', + $index3->getName() + ); + + $I->assertEquals( + ['column3'], + $index3->getColumns() + ); + + $index4 = $indexes['index4']; - $I->assertEquals($index4->getName(), 'index4'); - $I->assertEquals($index4->getColumns(), ['column4']); - $I->assertEquals($index4->getType(), 'UNIQUE'); + + $I->assertEquals( + 'index4', + $index4->getName() + ); + + $I->assertEquals( + ['column4'], + $index4->getColumns() + ); + + $I->assertEquals( + 'UNIQUE', + $index4->getType() + ); + + $index5 = $indexes['index5']; - $I->assertEquals($index5->getName(), 'index5'); - $I->assertEquals($index5->getColumns(), ['column7']); - $I->assertEquals($index5->getType(), 'FULLTEXT'); + + $I->assertEquals( + 'index5', + $index5->getName() + ); + + $I->assertEquals( + ['column7'], + $index5->getColumns() + ); + + $I->assertEquals( + 'FULLTEXT', + $index5->getType() + ); } } diff --git a/tests/integration/Forms/Element/TextCest.php b/tests/integration/Forms/Element/TextCest.php index 098a6e1a367..0ab22a0bb75 100644 --- a/tests/integration/Forms/Element/TextCest.php +++ b/tests/integration/Forms/Element/TextCest.php @@ -11,6 +11,7 @@ namespace Phalcon\Test\Integration\Forms\Element; +use Codeception\Example; use IntegrationTester; use Phalcon\Forms\Element\Text; use Phalcon\Tag; @@ -41,54 +42,75 @@ public function _after(IntegrationTester $I) * * @issue https://github.com/phalcon/cphalcon/issues/10398 * @author Phalcon Team - * @since 2016-07-17 + * @since 2016-07-17name + * + * @dataProvider testCreatingTextElementWithNameSimilarToTheFormMethodsProvider */ - public function testCreatingTextElementWithNameSimilarToTheFormMethods(IntegrationTester $I) + public function testCreatingTextElementWithNameSimilarToTheFormMethods(IntegrationTester $I, Example $example) { - $examples = [ - 'validation', - 'action', - 'useroption', - 'useroptions', - 'entity', - 'elements', - 'messages', - 'messagesfor', - 'label', - 'value', - 'di', - 'eventsmanager', - ]; + $name = $example[0]; + + $element = new Text($name); + + - foreach ($examples as $name) { - $element = new Text($name); + $I->assertEquals( + $name, + $element->getName() + ); + + + + $expected = sprintf( + '', + $name, + $name + ); - $expected = $name; - $actual = $element->getName(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $element->render() + ); - $expected = sprintf('', $name, $name); - $actual = $element->render(); - $I->assertEquals($expected, $actual); + $I->assertNull( + $element->getValue() + ); + } - $actual = $element->getValue(); - $I->assertNull($actual); - }; + private function testCreatingTextElementWithNameSimilarToTheFormMethodsProvider(): array + { + return [ + ['validation'], + ['action'], + ['useroption'], + ['useroptions'], + ['entity'], + ['elements'], + ['messages'], + ['messagesfor'], + ['label'], + ['value'], + ['di'], + ['eventsmanager'], + ]; } public function testIssue1210(IntegrationTester $I) { $element = new Text("test"); + $element->setLabel("Test"); - $actual = $element->label(); - $expected = ''; - $I->assertEquals($expected, $actual); + $I->assertEquals( + '', + $element->label() + ); } public function testIssue2045(IntegrationTester $I) { $element = new Text("name"); + $element->setAttributes( [ "class" => "big-input", @@ -97,25 +119,29 @@ public function testIssue2045(IntegrationTester $I) $element->setAttribute("id", null); - $expected = ''; - $actual = $element->render(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + '', + $element->render() + ); } public function testPrepareAttributesNoDefault(IntegrationTester $I) { $element1 = new Text("name"); + $element1->setLabel("name"); - $actual = $element1->prepareAttributes( - [ - "class" => "big-input", - ] - ); $expected = [ "name", "class" => "big-input", ]; + + $actual = $element1->prepareAttributes( + [ + "class" => "big-input", + ] + ); + $I->assertEquals($expected, $actual); } @@ -123,12 +149,14 @@ public function testFormElementEmpty(IntegrationTester $I) { $element = new Text("name"); - $actual = $element->getLabel(); - $I->assertNull($actual); + $I->assertNull( + $element->getLabel() + ); - $expected = []; - $actual = $element->getAttributes(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + [], + $element->getAttributes() + ); } public function testFormElement(IntegrationTester $I) @@ -136,36 +164,61 @@ public function testFormElement(IntegrationTester $I) $element = new Text("name"); $element->setLabel('name'); - $element->setAttributes(['class' => 'big-input']); + + $element->setAttributes( + [ + 'class' => 'big-input', + ] + ); + $element->setAttribute('placeholder', 'Type the name'); - $expected = 'name'; - $actual = $element->getLabel(); - $I->assertEquals($expected, $actual); + + + + $I->assertEquals( + 'name', + $element->getLabel() + ); + + $expected = [ 'class' => 'big-input', 'placeholder' => 'Type the name', ]; - $actual = $element->getAttributes(); - $I->assertEquals($expected, $actual); - $expected = 'big-input'; - $actual = $element->getAttribute('class'); - $I->assertEquals($expected, $actual); + $actual = $element->getAttributes(); - $expected = 'Type the name'; - $actual = $element->getAttribute('placeholder', 'the name'); $I->assertEquals($expected, $actual); - $expected = 'en'; - $actual = $element->getAttribute('lang', 'en'); - $I->assertEquals($expected, $actual); + + + + $I->assertEquals( + 'big-input', + $element->getAttribute('class') + ); + + $I->assertEquals( + 'Type the name', + $element->getAttribute('placeholder', 'the name') + ); + + $I->assertEquals( + 'en', + $element->getAttribute('lang', 'en') + ); + + $element->setLabel(0); - $expected = ''; - $actual = $element->label(); - $I->assertEquals($expected, $actual); + + + $I->assertEquals( + '', + $element->label() + ); } public function testFormPrepareAttributes(IntegrationTester $I) @@ -176,6 +229,7 @@ public function testFormPrepareAttributes(IntegrationTester $I) $expected = ['name']; $actual = $element1->prepareAttributes(); + $I->assertEquals($expected, $actual); } @@ -184,10 +238,16 @@ public function testFormPrepareAttributesDefault(IntegrationTester $I) $element1 = new Text("name"); $element1->setLabel('name'); - $element1->setAttributes(['class' => 'big-input']); + + $element1->setAttributes( + [ + 'class' => 'big-input', + ] + ); $expected = ['name', 'class' => 'big-input']; $actual = $element1->prepareAttributes(); + $I->assertEquals($expected, $actual); } @@ -195,22 +255,37 @@ public function testFormOptions(IntegrationTester $I) { $element1 = new Text("name"); - $element1->setAttributes(['class' => 'big-input']); - $element1->setUserOptions(['some' => 'value']); + $element1->setAttributes( + [ + 'class' => 'big-input', + ] + ); + + $element1->setUserOptions( + [ + 'some' => 'value', + ] + ); $expected = ['some' => 'value']; $actual = $element1->getUserOptions(); - $I->assertEquals($expected, $actual); - $expected = 'value'; - $actual = $element1->getUserOption('some'); $I->assertEquals($expected, $actual); - $actual = $element1->getUserOption('some-non'); - $I->assertNull($actual); - $expected = 'default'; - $actual = $element1->getUserOption('some-non', 'default'); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 'value', + $element1->getUserOption('some') + ); + + $I->assertNull( + $element1->getUserOption('some-non') + ); + + $I->assertEquals( + 'default', + $element1->getUserOption('some-non', 'default') + ); } } diff --git a/tests/integration/Forms/Form/AddCest.php b/tests/integration/Forms/Form/AddCest.php index 05bbe7dab14..2050c5b5c5d 100644 --- a/tests/integration/Forms/Form/AddCest.php +++ b/tests/integration/Forms/Form/AddCest.php @@ -41,6 +41,7 @@ public function formsFormAdd(IntegrationTester $I) public function testIssue706(IntegrationTester $I) { $form = new Form(); + $form->add(new Text("name")); $form->add(new Text("before"), "name", true); @@ -52,6 +53,7 @@ public function testIssue706(IntegrationTester $I) foreach ($form as $element) { $actual[] = $element->getName(); } + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Forms/Form/ClearCest.php b/tests/integration/Forms/Form/ClearCest.php index da2fb61ec08..05b73067c9a 100644 --- a/tests/integration/Forms/Form/ClearCest.php +++ b/tests/integration/Forms/Form/ClearCest.php @@ -37,7 +37,10 @@ class ClearCest public function _before(IntegrationTester $I) { Tag::resetInput(); - Tag::setDocType(Tag::HTML5); + + Tag::setDocType( + Tag::HTML5 + ); } /** @@ -70,17 +73,25 @@ public function clearFormElements(IntegrationTester $I) $eml = new Email('email'); $text = new Text('name'); + $text->setDefault('Serghei Iakovlev'); $form = new Form; + $form ->add($eml) ->add($text) ->add($pass) ; - $I->assertNull($form->get('passwd')->getValue()); - $I->assertEquals('Serghei Iakovlev', $form->get('name')->getValue()); + $I->assertNull( + $form->get('passwd')->getValue() + ); + + $I->assertEquals( + 'Serghei Iakovlev', + $form->get('name')->getValue() + ); $I->assertEquals( '', @@ -102,9 +113,20 @@ public function clearFormElements(IntegrationTester $I) 'name' => 'Andres Gutierrez', ]; - $I->assertEquals('secret', $form->get('passwd')->getValue()); - $I->assertEquals($pass->getValue(), $form->get('passwd')->getValue()); - $I->assertEquals('Andres Gutierrez', $form->get('name')->getValue()); + $I->assertEquals( + 'secret', + $form->get('passwd')->getValue() + ); + + $I->assertEquals( + $pass->getValue(), + $form->get('passwd')->getValue() + ); + + $I->assertEquals( + 'Andres Gutierrez', + $form->get('name')->getValue() + ); $I->assertEquals( '', @@ -123,7 +145,11 @@ public function clearFormElements(IntegrationTester $I) '', $form->render('email') ); - $I->assertEquals('andres@phalconphp.com', $form->get('email')->getValue()); + + $I->assertEquals( + 'andres@phalconphp.com', + $form->get('email')->getValue() + ); $pass->clear(); @@ -132,13 +158,25 @@ public function clearFormElements(IntegrationTester $I) $form->render('passwd') ); - $I->assertNull($pass->getValue()); - $I->assertEquals($pass->getValue(), $form->get('passwd')->getValue()); + $I->assertNull( + $pass->getValue() + ); + + $I->assertEquals( + $pass->getValue(), + $form->get('passwd')->getValue() + ); $form->clear(); - $I->assertEquals('Serghei Iakovlev', $form->get('name')->getValue()); - $I->assertNull($form->get('email')->getValue()); + $I->assertEquals( + 'Serghei Iakovlev', + $form->get('name')->getValue() + ); + + $I->assertNull( + $form->get('email')->getValue() + ); $I->assertEquals( '', @@ -150,7 +188,10 @@ public function clearFormElements(IntegrationTester $I) $form->render('email') ); - $I->assertEquals(['passwd' => 'secret', 'name' => 'Andres Gutierrez'], $_POST); + $I->assertEquals( + ['passwd' => 'secret', 'name' => 'Andres Gutierrez'], + $_POST + ); } /** @@ -164,33 +205,59 @@ public function clearFormElements(IntegrationTester $I) */ public function clearFormElementsAndUsingValidation(IntegrationTester $I) { - $password = new Password('password', ['placeholder' => 'Insert your Password']); + $password = new Password( + 'password', + [ + 'placeholder' => 'Insert your Password', + ] + ); $password->addValidators( [ - new PresenceOf(['message' => 'The field is required', 'cancelOnFail' => true]), - new StringLength(['min' => 7, 'messageMinimum' => 'The text is too short']), + new PresenceOf( + [ + 'message' => 'The field is required', + 'cancelOnFail' => true, + ] + ), + new StringLength( + [ + 'min' => 7, + 'messageMinimum' => 'The text is too short', + ] + ), ] ); $form = new Form; + $form->add($password); - $I->assertNull($form->get('password')->getValue()); + $I->assertNull( + $form->get('password')->getValue() + ); - $input = ''; - $I->assertEquals($input, $form->render('password')); + $I->assertEquals( + '', + $form->render('password') + ); $_POST = ['password' => 'secret']; - $I->assertEquals('secret', $form->get('password')->getValue()); + $I->assertEquals( + 'secret', + $form->get('password')->getValue() + ); - $input = ''; - $I->assertEquals($input, $form->render('password')); + $I->assertEquals( + '', + $form->render('password') + ); - $I->assertFalse($form->isValid($_POST)); + $I->assertFalse( + $form->isValid($_POST) + ); - $actual = $form->getMessages(); $expected = new Messages( [ new Message( @@ -201,16 +268,31 @@ public function clearFormElementsAndUsingValidation(IntegrationTester $I) ), ] ); - $I->assertEquals($actual, $expected); - $form->clear(['password']); + $I->assertEquals( + $expected, + $form->getMessages() + ); - $I->assertNull($form->get('password')->getValue()); + $form->clear( + ['password'] + ); - $input = ''; - $I->assertEquals($input, $form->render('password')); + $I->assertNull( + $form->get('password')->getValue() + ); - $I->assertEquals(['password' => 'secret'], $_POST); + $I->assertEquals( + '', + $form->render('password') + ); + + $I->assertEquals( + [ + 'password' => 'secret', + ], + $_POST + ); } /** @@ -228,6 +310,7 @@ public function clearFormElementsByUsingFormBind(IntegrationTester $I) $text = new Text('sel_text'); $form = new Form; + $form ->add($name) ->add($text) @@ -235,54 +318,160 @@ public function clearFormElementsByUsingFormBind(IntegrationTester $I) $entity = new MvcModel(); - $I->assertNull(Tag::getValue('sel_name')); - $I->assertNull($form->getValue('sel_name')); - $I->assertNull($form->get('sel_name')->getValue()); - $I->assertNull($name->getValue()); + $I->assertNull( + Tag::getValue('sel_name') + ); + + $I->assertNull( + $form->getValue('sel_name') + ); + + $I->assertNull( + $form->get('sel_name')->getValue() + ); + + $I->assertNull( + $name->getValue() + ); Tag::setDefault('sel_name', 'Please specify name'); - $_POST = ['sel_name' => 'Some Name', 'sel_text' => 'Some Text']; + + $_POST = [ + 'sel_name' => 'Some Name', + 'sel_text' => 'Some Text', + ]; $form->bind($_POST, $entity); - $I->assertEquals('Some Name', $entity->getName()); - $I->assertEquals('Some Text', $entity->getText()); + $I->assertEquals( + 'Some Name', + $entity->getName() + ); + + $I->assertEquals( + 'Some Text', + $entity->getText() + ); + + $I->assertEquals( + 'Some Name', + $form->getValue('sel_name') + ); + + $I->assertEquals( + 'Some Name', + $form->get('sel_name')->getValue() + ); + + $I->assertEquals( + 'Some Name', + $name->getValue() + ); + + $I->assertEquals( + 'Some Text', + $form->getValue('sel_text') + ); - $I->assertEquals('Some Name', $form->getValue('sel_name')); - $I->assertEquals('Some Name', $form->get('sel_name')->getValue()); - $I->assertEquals('Some Name', $name->getValue()); + $I->assertEquals( + 'Some Text', + $form->get('sel_text')->getValue() + ); - $I->assertEquals('Some Text', $form->getValue('sel_text')); - $I->assertEquals('Some Text', $form->get('sel_text')->getValue()); - $I->assertEquals('Some Text', $text->getValue()); + $I->assertEquals( + 'Some Text', + $text->getValue() + ); $form->clear(['sel_name']); - $I->assertNull(Tag::getValue('sel_name')); - $I->assertNull($form->getValue('sel_name')); - $I->assertNull($form->get('sel_name')->getValue()); - $I->assertNull($name->getValue()); + $I->assertNull( + Tag::getValue('sel_name') + ); + + $I->assertNull( + $form->getValue('sel_name') + ); + + $I->assertNull( + $form->get('sel_name')->getValue() + ); - $I->assertEquals('Some Text', $form->getValue('sel_text')); - $I->assertEquals('Some Text', $form->get('sel_text')->getValue()); - $I->assertEquals('Some Text', $text->getValue()); + $I->assertNull( + $name->getValue() + ); - $form->clear(['non_existent', 'another_filed']); + $I->assertEquals( + 'Some Text', + $form->getValue('sel_text') + ); - $I->assertEquals('Some Text', $form->getValue('sel_text')); - $I->assertEquals('Some Text', $form->get('sel_text')->getValue()); - $I->assertEquals('Some Text', $text->getValue()); + $I->assertEquals( + 'Some Text', + $form->get('sel_text')->getValue() + ); + + $I->assertEquals( + 'Some Text', + $text->getValue() + ); + + $form->clear( + [ + 'non_existent', + 'another_filed', + ] + ); + + $I->assertEquals( + 'Some Text', + $form->getValue('sel_text') + ); + + $I->assertEquals( + 'Some Text', + $form->get('sel_text')->getValue() + ); + + $I->assertEquals( + 'Some Text', + $text->getValue() + ); $form->clear(); - $I->assertNull(Tag::getValue('sel_text')); - $I->assertNull($form->getValue('sel_text')); - $I->assertNull($form->get('sel_text')->getValue()); - $I->assertNull($text->getValue()); + $I->assertNull( + Tag::getValue('sel_text') + ); + + $I->assertNull( + $form->getValue('sel_text') + ); + + $I->assertNull( + $form->get('sel_text')->getValue() + ); - $I->assertEquals('Some Name', $entity->getName()); - $I->assertEquals('Some Text', $entity->getText()); + $I->assertNull( + $text->getValue() + ); - $I->assertEquals(['sel_name' => 'Some Name', 'sel_text' => 'Some Text'], $_POST); + $I->assertEquals( + 'Some Name', + $entity->getName() + ); + + $I->assertEquals( + 'Some Text', + $entity->getText() + ); + + $I->assertEquals( + [ + 'sel_name' => 'Some Name', + 'sel_text' => 'Some Text', + ], + $_POST + ); } } diff --git a/tests/integration/Forms/Form/CountCest.php b/tests/integration/Forms/Form/CountCest.php index 0d0f3f4c892..8527cdc693d 100644 --- a/tests/integration/Forms/Form/CountCest.php +++ b/tests/integration/Forms/Form/CountCest.php @@ -35,9 +35,7 @@ public function formsFormCount(IntegrationTester $I) $form = new Form(); - $expected = 0; - $actual = count($form); - $I->assertEquals($expected, $actual); + $I->assertCount(0, $form); $form->add( new Text("name") @@ -47,8 +45,6 @@ public function formsFormCount(IntegrationTester $I) new Text("telephone") ); - $expected = 2; - $actual = count($form); - $I->assertEquals($expected, $actual); + $I->assertCount(2, $form); } } diff --git a/tests/integration/Forms/Form/GetMessagesCest.php b/tests/integration/Forms/Form/GetMessagesCest.php index d792ec2d48a..628ef151e09 100644 --- a/tests/integration/Forms/Form/GetMessagesCest.php +++ b/tests/integration/Forms/Form/GetMessagesCest.php @@ -60,6 +60,7 @@ public function testGetElementMessagesFromForm(IntegrationTester $I) { // First element $telephone = new Text('telephone'); + $telephone->addValidators( [ new PresenceOf( @@ -69,7 +70,9 @@ public function testGetElementMessagesFromForm(IntegrationTester $I) ), ] ); + $customValidation = new Validation(); + $customValidation->add( 'telephone', new Regex( @@ -79,13 +82,20 @@ public function testGetElementMessagesFromForm(IntegrationTester $I) ] ) ); + $form = new Form(); $address = new Text('address'); + $form->add($telephone); $form->add($address); $form->setValidation($customValidation); - $actual = $form->isValid(['address' => 'hello']); + $actual = $form->isValid( + [ + 'address' => 'hello', + ] + ); + $I->assertFalse($actual); $expected = [ @@ -112,7 +122,9 @@ public function testGetElementMessagesFromForm(IntegrationTester $I) ), ], ]; - $actual = $form->getMessages(true); + + $actual = $form->getMessages(true); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Forms/Form/HasMessagesForCest.php b/tests/integration/Forms/Form/HasMessagesForCest.php index 3177aa22b54..cc4d15d85e6 100644 --- a/tests/integration/Forms/Form/HasMessagesForCest.php +++ b/tests/integration/Forms/Form/HasMessagesForCest.php @@ -55,6 +55,7 @@ public function testFormHasMessagesFor(IntegrationTester $I) { // First element $telephone = new Text('telephone'); + $telephone->addValidators( [ new Regex( @@ -73,9 +74,17 @@ public function testFormHasMessagesFor(IntegrationTester $I) $form->add($telephone); $form->add($address); - $actual = $form->isValid(['telephone' => '12345', 'address' => 'hello']); + $actual = $form->isValid( + [ + 'telephone' => '12345', + 'address' => 'hello', + ] + ); + $I->assertFalse($actual); + + $expected = new Messages( [ new Message( @@ -86,17 +95,28 @@ public function testFormHasMessagesFor(IntegrationTester $I) ), ] ); - $actual = $form->getMessagesFor('telephone'); + + $actual = $form->getMessagesFor('telephone'); + $I->assertEquals($expected, $actual); + + $expected = new Messages(); $actual = $form->getMessagesFor('address'); + $I->assertEquals($expected, $actual); + + $actual = $form->hasMessagesFor('telephone'); + $I->assertTrue($actual); + + $actual = $form->hasMessagesFor('address'); + $I->assertFalse($actual); } } diff --git a/tests/integration/Forms/Form/IsValidCest.php b/tests/integration/Forms/Form/IsValidCest.php index 2d950dfc443..4b4368077b4 100644 --- a/tests/integration/Forms/Form/IsValidCest.php +++ b/tests/integration/Forms/Form/IsValidCest.php @@ -56,6 +56,7 @@ public function testMergeValidators(IntegrationTester $I) { // First element $telephone = new Text('telephone'); + $telephone->addValidators( [ new PresenceOf( @@ -65,7 +66,9 @@ public function testMergeValidators(IntegrationTester $I) ), ] ); + $customValidation = new Validation(); + $customValidation->add( 'telephone', new Regex( @@ -75,21 +78,40 @@ public function testMergeValidators(IntegrationTester $I) ] ) ); - $form = new Form(); + + $form = new Form(); + $address = new Text('address'); + $form->add($telephone); $form->add($address); + $form->setValidation($customValidation); - $actual = $form->isValid(['address' => 'hello']); + + + $actual = $form->isValid( + [ + 'address' => 'hello', + ] + ); + $I->assertFalse($actual); + + $actual = $form->get('telephone')->hasMessages(); + $I->assertTrue($actual); + + $actual = $form->get('address')->hasMessages(); + $I->assertFalse($actual); + + $expected = new Messages( [ new Message( @@ -106,15 +128,23 @@ public function testMergeValidators(IntegrationTester $I) ), ] ); - $actual = $form->get('telephone')->getMessages(); + + $actual = $form->get('telephone')->getMessages(); + $I->assertEquals($expected, $actual); + + $expected = $form->getMessages(); $actual = $form->get('telephone')->getMessages(); + $I->assertEquals($expected, $actual); + + $expected = new Messages(); $actual = $form->get('address')->getMessages(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Forms/Form/RenderCest.php b/tests/integration/Forms/Form/RenderCest.php index d740477326c..b6476dddf17 100644 --- a/tests/integration/Forms/Form/RenderCest.php +++ b/tests/integration/Forms/Form/RenderCest.php @@ -69,17 +69,33 @@ public function testCreatingElementsWithNameSimilarToTheFormMethods(IntegrationT $form = new Form; $element = new Text($name); + + $expected = $name; $actual = $element->getName(); + $I->assertEquals($expected, $actual); + + $form->add($element); - $expected = sprintf('', $name, $name); - $actual = $form->render($name); + + + $expected = sprintf( + '', + $name, + $name + ); + + $actual = $form->render($name); + $I->assertEquals($expected, $actual); + + $actual = $form->getValue($name); + $I->assertNull($actual); } } @@ -88,14 +104,26 @@ public function testFormIndirectElementRender(IntegrationTester $I) { $form = new Form(); - $form->add(new Text("name")); + $form->add( + new Text("name") + ); $expected = ''; $actual = $form->render("name"); + $I->assertEquals($expected, $actual); + + $expected = ''; - $actual = $form->render("name", ["class" => "big-input"]); + + $actual = $form->render( + "name", + [ + "class" => "big-input", + ] + ); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Forms/Form/SetValidationCest.php b/tests/integration/Forms/Form/SetValidationCest.php index 4eaed99590e..624abf3b438 100644 --- a/tests/integration/Forms/Form/SetValidationCest.php +++ b/tests/integration/Forms/Form/SetValidationCest.php @@ -54,8 +54,10 @@ public function _after(IntegrationTester $I) public function testCustomValidation(IntegrationTester $I) { // First element - $telephone = new Text('telephone'); + $telephone = new Text('telephone'); + $customValidation = new Validation(); + $customValidation->add( 'telephone', new Regex( @@ -65,21 +67,40 @@ public function testCustomValidation(IntegrationTester $I) ] ) ); + $form = new Form(); $address = new Text('address'); + $form->add($telephone); $form->add($address); + $form->setValidation($customValidation); - $actual = $form->isValid(['telephone' => '12345', 'address' => 'hello']); + + + $actual = $form->isValid( + [ + 'telephone' => '12345', + 'address' => 'hello', + ] + ); + $I->assertFalse($actual); + + $actual = $form->get('telephone')->hasMessages(); + $I->assertTrue($actual); + + $actual = $form->get('address')->hasMessages(); + $I->assertFalse($actual); + + $expected = new Messages( [ new Message( @@ -90,15 +111,23 @@ public function testCustomValidation(IntegrationTester $I) ), ] ); - $actual = $form->get('telephone')->getMessages(); + + $actual = $form->get('telephone')->getMessages(); + $I->assertEquals($expected, $actual); + + $expected = $form->getMessages(); $actual = $form->get('telephone')->getMessages(); + $I->assertEquals($expected, $actual); + + $expected = new Messages(); $actual = $form->get('address')->getMessages(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Forms/FormCest.php b/tests/integration/Forms/FormCest.php index 97ff49fd467..b82ea7d3cd6 100644 --- a/tests/integration/Forms/FormCest.php +++ b/tests/integration/Forms/FormCest.php @@ -40,7 +40,9 @@ public function _before(IntegrationTester $I) public function _after(IntegrationTester $I) { // Setting the doctype to XHTML5 for other tests to run smoothly - Tag::setDocType(Tag::XHTML5); + Tag::setDocType( + Tag::XHTML5 + ); } public function testIterator(IntegrationTester $I) @@ -52,10 +54,15 @@ public function testIterator(IntegrationTester $I) $data[$key] = $value->getName(); } + + $expected = []; $actual = $data; + $I->assertEquals($expected, $actual); + + $form->add( new Text("name") ); @@ -68,11 +75,15 @@ public function testIterator(IntegrationTester $I) $data[$key] = $value->getName(); } + + $expected = [ 0 => "name", 1 => "telephone", ]; - $actual = $data; + + $actual = $data; + $I->assertEquals($expected, $actual); } @@ -85,32 +96,64 @@ public function testLabels(IntegrationTester $I) ); $telephone = new Text("telephone"); + $telephone->setLabel("The Telephone"); + $form->add($telephone); + + $expected = 'name'; $actual = $form->getLabel("name"); + $I->assertEquals($expected, $actual); + + $expected = 'The Telephone'; $actual = $form->getLabel("telephone"); + $I->assertEquals($expected, $actual); + + $expected = ""; $actual = $form->label("name"); + $I->assertEquals($expected, $actual); + + $expected = ""; $actual = $form->label("telephone"); + $I->assertEquals($expected, $actual); + + // https://github.com/phalcon/cphalcon/issues/1029 $expected = ""; - $actual = $form->label("name", ["class" => "form-control"]); + + $actual = $form->label( + "name", + [ + "class" => "form-control", + ] + ); + $I->assertEquals($expected, $actual); + + $expected = ""; - $actual = $form->label("telephone", ["class" => "form-control"]); + + $actual = $form->label( + "telephone", + [ + "class" => "form-control", + ] + ); + $I->assertEquals($expected, $actual); } @@ -118,6 +161,7 @@ public function testFormValidator(IntegrationTester $I) { //First element $telephone = new Text("telephone"); + $telephone->addValidator( new PresenceOf( [ @@ -126,9 +170,14 @@ public function testFormValidator(IntegrationTester $I) ) ); - $expected = 1; - $actual = count($telephone->getValidators()); - $I->assertEquals($expected, $actual); + + + $I->assertCount( + 1, + $telephone->getValidators() + ); + + $telephone->addValidators( [ @@ -147,12 +196,18 @@ public function testFormValidator(IntegrationTester $I) ] ); - $expected = 3; - $actual = count($telephone->getValidators()); - $I->assertEquals($expected, $actual); + + + $I->assertCount( + 3, + $telephone->getValidators() + ); + + //Second element $address = new Text('address'); + $address->addValidator( new PresenceOf( [ @@ -161,17 +216,30 @@ public function testFormValidator(IntegrationTester $I) ) ); - $expected = 3; - $actual = count($telephone->getValidators()); - $I->assertEquals($expected, $actual); + + + $I->assertCount( + 3, + $telephone->getValidators() + ); + + $form = new Form(); + $form->add($telephone); $form->add($address); - $actual = $form->isValid([]); + + + $actual = $form->isValid( + [] + ); + $I->assertFalse($actual); + + $expected = new Messages( [ new Message( @@ -200,17 +268,24 @@ public function testFormValidator(IntegrationTester $I) ), ] ); - $actual = $form->getMessages(); + + $actual = $form->getMessages(); + $I->assertEquals($expected, $actual); + + $actual = $form->isValid( [ 'telephone' => '12345', 'address' => 'hello', ] ); + $I->assertFalse($actual); + + $expected = new Messages( [ new Message( @@ -221,15 +296,20 @@ public function testFormValidator(IntegrationTester $I) ), ] ); - $actual = $form->getMessages(); + + $actual = $form->getMessages(); + $I->assertEquals($expected, $actual); + + $actual = $form->isValid( [ 'telephone' => '+44 124 82122', 'address' => 'hello', ] ); + $I->assertTrue($actual); } @@ -238,14 +318,19 @@ public function testFormValidator(IntegrationTester $I) */ public function testIssue1190(IntegrationTester $I) { - $object = new \stdClass(); + $object = new \stdClass(); + $object->title = 'Hello "world!"'; $form = new Form($object); - $form->add(new Text("title")); + + $form->add( + new Text("title") + ); $actual = $form->render("title"); $expected = ''; + $I->assertEquals($expected, $actual); } @@ -279,12 +364,28 @@ public function testElementMessages(IntegrationTester $I) $form->add($telephone); $form->add($address); - $actual = $form->isValid(['telephone' => '12345', 'address' => 'hello']); - $I->assertFalse($actual); - $actual = $form->get('telephone')->hasMessages(); - $I->assertTrue($actual); - $actual = $form->get('address')->hasMessages(); - $I->assertFalse($actual); + + + $I->assertFalse( + $form->isValid( + [ + 'telephone' => '12345', + 'address' => 'hello', + ] + ) + ); + + + + $I->assertTrue( + $form->get('telephone')->hasMessages() + ); + + $I->assertFalse( + $form->get('address')->hasMessages() + ); + + $expected = new Messages( [ @@ -296,19 +397,30 @@ public function testElementMessages(IntegrationTester $I) ), ] ); - $actual = $form->get('telephone')->getMessages(); + + $actual = $form->get('telephone')->getMessages(); + $I->assertEquals($expected, $actual); + + $expected = $form->getMessages(); $actual = $form->get('telephone')->getMessages(); + $I->assertEquals($expected, $actual); + + $expected = new Messages(); $actual = $form->get('address')->getMessages(); + $I->assertEquals($expected, $actual); + + $expected = new Messages(); $actual = $form->getMessagesFor('notelement'); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Forms/FormElementsCest.php b/tests/integration/Forms/FormElementsCest.php index 9ba18f14184..989fc190751 100644 --- a/tests/integration/Forms/FormElementsCest.php +++ b/tests/integration/Forms/FormElementsCest.php @@ -41,7 +41,10 @@ class FormElementsCest public function _before(IntegrationTester $I) { Tag::resetInput(); - Tag::setDocType(Tag::HTML5); + + Tag::setDocType( + Tag::HTML5 + ); } /** @@ -58,54 +61,82 @@ public function shouldCancelValidationOnFirstFail(IntegrationTester $I) $form = new Form(); $lastName = new Text('lastName'); + $lastName->setLabel('user.lastName'); - $lastName->setFilters([ - "string", - "striptags", - "trim", - ]); - - $lastName->addValidators([ - new PresenceOf([ - 'message' => 'user.lastName.presenceOf', - 'cancelOnFail' => true, - ]), - new StringLength([ - 'min' => 3, - 'max' => 255, - 'messageMaximum' => 'user.lastName.max', - 'messageMinimum' => 'user.lastName.min', - ]), - ]); + + $lastName->setFilters( + [ + "string", + "striptags", + "trim", + ] + ); + + $lastName->addValidators( + [ + new PresenceOf( + [ + 'message' => 'user.lastName.presenceOf', + 'cancelOnFail' => true, + ] + ), + new StringLength( + [ + 'min' => 3, + 'max' => 255, + 'messageMaximum' => 'user.lastName.max', + 'messageMinimum' => 'user.lastName.min', + ] + ), + ] + ); + + $firstName = new Text('firstName'); + $firstName->setLabel('user.firstName'); - $firstName->setFilters([ - "string", - "striptags", - "trim", - ]); - - $firstName->addValidators([ - new PresenceOf([ - 'message' => 'user.firstName.presenceOf', - 'cancelOnFail' => true, - ]), - new StringLength([ - 'min' => 3, - 'max' => 255, - 'messageMaximum' => 'user.firstName.max', - 'messageMinimum' => 'user.firstName.min', - ]), - ]); + + $firstName->setFilters( + [ + "string", + "striptags", + "trim", + ] + ); + + $firstName->addValidators( + [ + new PresenceOf( + [ + 'message' => 'user.firstName.presenceOf', + 'cancelOnFail' => true, + ] + ), + new StringLength( + [ + 'min' => 3, + 'max' => 255, + 'messageMaximum' => 'user.firstName.max', + 'messageMinimum' => 'user.firstName.min', + ] + ), + ] + ); $form->add($lastName); $form->add($firstName); + + $_POST = []; - $I->assertFalse($form->isValid($_POST)); - $actual = $form->getMessages(); + $I->assertFalse( + $form->isValid($_POST) + ); + + + $expected = new Messages( [ new Message( @@ -116,6 +147,9 @@ public function shouldCancelValidationOnFirstFail(IntegrationTester $I) ), ] ); - $I->assertEquals($actual, $expected); + + $actual = $form->getMessages(); + + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Forms/FormsCest.php b/tests/integration/Forms/FormsCest.php index 91a72eb103f..5704596997b 100644 --- a/tests/integration/Forms/FormsCest.php +++ b/tests/integration/Forms/FormsCest.php @@ -39,20 +39,48 @@ class FormsCest public function _before() { $this->setNewFactoryDefault(); - Tag::setDoctype(Tag::HTML5); + + Tag::setDoctype( + Tag::HTML5 + ); } public function testFormElementRender(IntegrationTester $I) { $element1 = new Text("name"); - $element1->setAttributes(['class' => 'big-input']); + + $element1->setAttributes( + [ + 'class' => 'big-input', + ] + ); + + $element2 = new Radio('radio'); - $element2->setAttributes(['value' => 0]); - $I->assertEquals('', $element1->render()); - $I->assertEquals('', (string) $element1); - $I->assertEquals('', (string) $element2); + $element2->setAttributes( + [ + 'value' => 0, + ] + ); + + + + $I->assertEquals( + '', + $element1->render() + ); + + $I->assertEquals( + '', + (string) $element1 + ); + + $I->assertEquals( + '', + (string) $element2 + ); } public function testFormRenderEntity(IntegrationTester $I) @@ -60,17 +88,27 @@ public function testFormRenderEntity(IntegrationTester $I) //Second element $address = new Text('address'); - $address->addValidator(new PresenceOf([ - 'message' => 'The address is required', - ])); + $address->addValidator( + new PresenceOf( + [ + 'message' => 'The address is required', + ] + ) + ); $telephone = new Text("telephone"); - $telephone->addValidator(new PresenceOf([ - 'message' => 'The telephone is required', - ])); + $telephone->addValidator( + new PresenceOf( + [ + 'message' => 'The telephone is required', + ] + ) + ); - $form = new Form(new ContactFormPublicProperties()); + $form = new Form( + new ContactFormPublicProperties() + ); $form->add($address); $form->add($telephone); @@ -91,17 +129,27 @@ public function testFormRenderEntityGetters(IntegrationTester $I) //Second element $address = new Text('address'); - $address->addValidator(new PresenceOf([ - 'message' => 'The address is required', - ])); + $address->addValidator( + new PresenceOf( + [ + 'message' => 'The address is required', + ] + ) + ); $telephone = new Text("telephone"); - $telephone->addValidator(new PresenceOf([ - 'message' => 'The telephone is required', - ])); + $telephone->addValidator( + new PresenceOf( + [ + 'message' => 'The telephone is required', + ] + ) + ); - $form = new Form(new ContactFormSettersGetters()); + $form = new Form( + new ContactFormSettersGetters() + ); $form->add($address); $form->add($telephone); @@ -122,25 +170,39 @@ public function testFormValidatorEntity(IntegrationTester $I) //Second element $address = new Text('address'); - $address->addValidator(new PresenceOf([ - 'message' => 'The address is required', - ])); + $address->addValidator( + new PresenceOf( + [ + 'message' => 'The address is required', + ] + ) + ); $telephone = new Text("telephone"); - $telephone->addValidator(new PresenceOf([ - 'message' => 'The telephone is required', - ])); + $telephone->addValidator( + new PresenceOf( + [ + 'message' => 'The telephone is required', + ] + ) + ); - $form = new Form(new ContactFormPublicProperties()); + $form = new Form( + new ContactFormPublicProperties() + ); $form->add($address); $form->add($telephone); - $I->assertTrue($form->isValid([ - 'telephone' => '+44 124 82122', - 'address' => 'hello', - ])); + $I->assertTrue( + $form->isValid( + [ + 'telephone' => '+44 124 82122', + 'address' => 'hello', + ] + ) + ); } public function testFormValidatorEntityBind(IntegrationTester $I) @@ -148,15 +210,23 @@ public function testFormValidatorEntityBind(IntegrationTester $I) //Second element $address = new Text('address'); - $address->addValidator(new PresenceOf([ - 'message' => 'The address is required', - ])); + $address->addValidator( + new PresenceOf( + [ + 'message' => 'The address is required', + ] + ) + ); $telephone = new Text("telephone"); - $telephone->addValidator(new PresenceOf([ - 'message' => 'The telephone is required', - ])); + $telephone->addValidator( + new PresenceOf( + [ + 'message' => 'The telephone is required', + ] + ) + ); $entity = new ContactFormPublicProperties(); @@ -165,10 +235,13 @@ public function testFormValidatorEntityBind(IntegrationTester $I) $form->add($address); $form->add($telephone); - $form->bind([ - 'telephone' => '+44 123 45678', - 'address' => 'hello', - ], $entity); + $form->bind( + [ + 'telephone' => '+44 123 45678', + 'address' => 'hello', + ], + $entity + ); $I->assertTrue($form->isValid()); @@ -181,15 +254,23 @@ public function testFormValidatorEntityBindSetters(IntegrationTester $I) //Second element $address = new Text('address'); - $address->addValidator(new PresenceOf([ - 'message' => 'The address is required', - ])); + $address->addValidator( + new PresenceOf( + [ + 'message' => 'The address is required', + ] + ) + ); $telephone = new Text("telephone"); - $telephone->addValidator(new PresenceOf([ - 'message' => 'The telephone is required', - ])); + $telephone->addValidator( + new PresenceOf( + [ + 'message' => 'The telephone is required', + ] + ) + ); $entity = new ContactFormSettersGetters(); @@ -198,25 +279,48 @@ public function testFormValidatorEntityBindSetters(IntegrationTester $I) $form->add($address); $form->add($telephone); - $form->bind([ - 'telephone' => '+44 123 45678', - 'address' => 'hello', - ], $entity); + $form->bind( + [ + 'telephone' => '+44 123 45678', + 'address' => 'hello', + ], + $entity + ); + - $I->assertTrue($form->isValid()); - $I->assertEquals($entity->getTelephone(), '+44 123 45678'); - $I->assertEquals($entity->getAddress(), 'hello'); + $I->assertTrue( + $form->isValid() + ); + + $I->assertEquals( + '+44 123 45678', + $entity->getTelephone() + ); + + $I->assertEquals( + 'hello', + $entity->getAddress() + ); } public function testCorrectlyAddOptionToSelectElementIfParameterIsAnArray(IntegrationTester $I) { $element = new Select('test-select'); - $element->addOption(['key' => 'value']); + + $element->addOption( + [ + 'key' => 'value', + ] + ); $I->assertEquals( '', - preg_replace('/[[:cntrl:]]/', '', $element->render()) + preg_replace( + '/[[:cntrl:]]/', + '', + $element->render() + ) ); } @@ -227,13 +331,20 @@ public function testCorrectlyAddOptionToSelectElementIfParameterIsAString(Integr $I->assertEquals( '', - preg_replace('/[[:cntrl:]]/', '', $element->render()) + preg_replace( + '/[[:cntrl:]]/', + '', + $element->render() + ) ); } public function testElementAppendMessage(IntegrationTester $I) { $element = new Select('test-select'); - $element->appendMessage(new Message('')); + + $element->appendMessage( + new Message('') + ); } } diff --git a/tests/integration/Mvc/Dispatcher/Helper/BaseDispatcher.php b/tests/integration/Mvc/Dispatcher/Helper/BaseDispatcher.php index 11b880b84cf..b4c09371cba 100644 --- a/tests/integration/Mvc/Dispatcher/Helper/BaseDispatcher.php +++ b/tests/integration/Mvc/Dispatcher/Helper/BaseDispatcher.php @@ -46,9 +46,19 @@ public function _before(IntegrationTester $I) $dispatcherListener = new DispatcherListener(); Di::reset(); + $this->di = new Di(); - $this->di->setShared('response', new Response()); - $this->di->setShared('dispatcherListener', $dispatcherListener); + + $this->di->setShared( + 'response', + new Response() + ); + + $this->di->setShared( + 'dispatcherListener', + $dispatcherListener + ); + $this->di->setShared( 'dispatcher', function () use ($dispatcherListener) { @@ -62,7 +72,12 @@ function () use ($dispatcherListener) { // Ensure this gets called prior to any custom event listening which has a default priority of 100 $eventsManager = new EventsManager(); - $eventsManager->attach('dispatch', $dispatcherListener, 200); + + $eventsManager->attach( + 'dispatch', + $dispatcherListener, + 200 + ); $dispatcher->setEventsManager($eventsManager); diff --git a/tests/integration/Mvc/Dispatcher/Helper/DispatcherListener.php b/tests/integration/Mvc/Dispatcher/Helper/DispatcherListener.php index 435f0d2ec30..d4e687c7011 100644 --- a/tests/integration/Mvc/Dispatcher/Helper/DispatcherListener.php +++ b/tests/integration/Mvc/Dispatcher/Helper/DispatcherListener.php @@ -92,6 +92,8 @@ public function beforeNotFoundAction(Event $event, DispatcherInterface $dispatch public function beforeException(Event $event, DispatcherInterface $dispatcher, Exception $exception) { - $this->trace('beforeException: ' . $exception->getMessage()); + $this->trace( + 'beforeException: ' . $exception->getMessage() + ); } } diff --git a/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestAfterExecuteRouteForwardController.php b/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestAfterExecuteRouteForwardController.php index 10d197c0b58..5af7a81d84f 100644 --- a/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestAfterExecuteRouteForwardController.php +++ b/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestAfterExecuteRouteForwardController.php @@ -50,10 +50,15 @@ public function afterExecuteRoute() { $this->trace('afterExecuteRoute-method'); - $this->getDI()->getShared('dispatcher')->forward([ - 'controller' => 'dispatcher-test-default', - 'action' => 'index', - ]) - ; + $di = $this->getDI(); + + $dispatcher = $di->getShared('dispatcher'); + + $dispatcher->forward( + [ + 'controller' => 'dispatcher-test-default', + 'action' => 'index', + ] + ); } } diff --git a/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestBeforeExecuteRouteForwardController.php b/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestBeforeExecuteRouteForwardController.php index 2151b7d8327..57a05c657ed 100644 --- a/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestBeforeExecuteRouteForwardController.php +++ b/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestBeforeExecuteRouteForwardController.php @@ -40,11 +40,16 @@ public function beforeExecuteRoute() { $this->trace('beforeExecuteRoute-method'); - $this->getDI()->getShared('dispatcher')->forward([ - 'controller' => 'dispatcher-test-default', - 'action' => 'index', - ]) - ; + $di = $this->getDI(); + + $dispatcher = $di->getShared('dispatcher'); + + $dispatcher->forward( + [ + 'controller' => 'dispatcher-test-default', + 'action' => 'index', + ] + ); } public function indexAction() diff --git a/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestDefaultController.php b/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestDefaultController.php index 9de81e5d7eb..aa071b2d20d 100644 --- a/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestDefaultController.php +++ b/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestDefaultController.php @@ -79,25 +79,38 @@ public function multiplyAction($a, $b) public function forwardLocalAction() { $this->trace('forwardLocalAction'); - $this->getDI()->getShared('dispatcher')->forward([ - 'action' => 'index2', - ]) - ; + + $di = $this->getDI(); + + $dispatcher = $di->getShared('dispatcher'); + + $dispatcher->forward( + [ + 'action' => 'index2', + ] + ); } public function forwardExternalAction() { $this->trace('forwardExternalAction'); - $this->getDI()->getShared('dispatcher')->forward([ - 'controller' => 'dispatcher-test-default-two', - 'action' => 'index', - ]) - ; + + $di = $this->getDI(); + + $dispatcher = $di->getShared('dispatcher'); + + $dispatcher->forward( + [ + 'controller' => 'dispatcher-test-default-two', + 'action' => 'index', + ] + ); } public function exceptionAction() { $this->trace('exceptionAction'); + throw new Exception('An exception occurred.'); } diff --git a/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestDefaultNoNamespaceController.php b/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestDefaultNoNamespaceController.php index 22ee5e90144..d18516458f4 100644 --- a/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestDefaultNoNamespaceController.php +++ b/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestDefaultNoNamespaceController.php @@ -58,26 +58,39 @@ public function index2Action() public function forwardLocalAction() { $this->trace('forwardLocalAction'); - $this->getDI()->getShared('dispatcher')->forward([ - 'action' => 'index2', - ]) - ; + + $di = $this->getDI(); + + $dispatcher = $di->getShared('dispatcher'); + + $dispatcher->forward( + [ + 'action' => 'index2', + ] + ); } public function forwardExternalAction() { $this->trace('forwardExternalAction'); - $this->getDI()->getShared('dispatcher')->forward([ - 'namespace' => 'Phalcon\Test\Integration\Mvc\Dispatcher\Helper', - 'controller' => 'dispatcher-test-default', - 'action' => 'index', - ]) - ; + + $di = $this->getDI(); + + $dispatcher = $di->getShared('dispatcher'); + + $dispatcher->forward( + [ + 'namespace' => 'Phalcon\Test\Integration\Mvc\Dispatcher\Helper', + 'controller' => 'dispatcher-test-default', + 'action' => 'index', + ] + ); } public function exceptionAction() { $this->trace('exceptionAction'); + throw new Exception('An exception occurred.'); } diff --git a/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestDefaultTwoController.php b/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestDefaultTwoController.php index 135af817cb8..be06fdc9385 100644 --- a/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestDefaultTwoController.php +++ b/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestDefaultTwoController.php @@ -54,25 +54,38 @@ public function index2Action() public function forwardLocalAction() { $this->trace('forwardLocalAction'); - $this->getDI()->getShared('dispatcher')->forward([ - 'action' => 'index2', - ]) - ; + + $di = $this->getDI(); + + $dispatcher = $di->getShared('dispatcher'); + + $dispatcher->forward( + [ + 'action' => 'index2', + ] + ); } public function forwardExternalAction() { $this->trace('forwardExternalAction'); - $this->getDI()->getShared('dispatcher')->forward([ - 'controller' => 'dispatcher-test-default', - 'action' => 'index', - ]) - ; + + $di = $this->getDI(); + + $dispatcher = $di->getShared('dispatcher'); + + $dispatcher->forward( + [ + 'controller' => 'dispatcher-test-default', + 'action' => 'index', + ] + ); } public function exceptionAction() { $this->trace('exceptionAction'); + throw new Exception('An exception occurred.'); } diff --git a/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestInitializeForwardController.php b/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestInitializeForwardController.php index a6d38eaa1ff..258fa7fc93c 100644 --- a/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestInitializeForwardController.php +++ b/tests/integration/Mvc/Dispatcher/Helper/DispatcherTestInitializeForwardController.php @@ -40,11 +40,16 @@ public function initialize() { $this->trace('initialize-method'); - $this->getDI()->getShared('dispatcher')->forward([ - 'controller' => 'dispatcher-test-default', - 'action' => 'index', - ]) - ; + $di = $this->getDI(); + + $dispatcher = $di->getShared('dispatcher'); + + $dispatcher->forward( + [ + 'controller' => 'dispatcher-test-default', + 'action' => 'index', + ] + ); } public function afterExecuteRoute() diff --git a/tests/integration/Mvc/Dispatcher/Refactor-DispatcherBeforeDispatchLoopCest.php b/tests/integration/Mvc/Dispatcher/Refactor-DispatcherBeforeDispatchLoopCest.php index d9748b432fa..95a956cebc9 100644 --- a/tests/integration/Mvc/Dispatcher/Refactor-DispatcherBeforeDispatchLoopCest.php +++ b/tests/integration/Mvc/Dispatcher/Refactor-DispatcherBeforeDispatchLoopCest.php @@ -41,10 +41,13 @@ public function testBeforeDispatchLoopForward(IntegrationTester $I) $dispatcher->getEventsManager()->attach( 'dispatch:beforeDispatchLoop', function ($event, $dispatcher) { - $dispatcher->forward(['action' => 'index2']); + $dispatcher->forward( + [ + 'action' => 'index2', + ] + ); } - ) - ; + ); $dispatcher->dispatch(); @@ -61,7 +64,9 @@ function ($event, $dispatcher) { 'afterDispatch', 'afterDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -75,16 +80,21 @@ public function testBeforeDispatchLoopReturnFalse(IntegrationTester $I) { $dispatcher = $this->getDispatcher(); - $dispatcher->getEventsManager()->attach('dispatch:beforeDispatchLoop', function () { - return false; - }) - ; + $dispatcher->getEventsManager()->attach( + 'dispatch:beforeDispatchLoop', + function () { + return false; + } + ); + $dispatcher->dispatch(); $expected = [ 'beforeDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -108,17 +118,22 @@ public function testBeforeDispatchLoopBaselinePrePhalcon40MultipleReturnFalseMix { $dispatcher = $this->getDispatcher(); - $dispatcher->getEventsManager()->attach('dispatch:beforeDispatchLoop', function () { - return false; - }) - ; + $dispatcher->getEventsManager()->attach( + 'dispatch:beforeDispatchLoop', + function () { + return false; + } + ); + // Unfortunately, we really need to collect all responses or use the Event stopping property // instead of return false. The following statement breaks the ability to stop the chain. - $dispatcher->getEventsManager()->attach('dispatch:beforeDispatchLoop', function () { - return true; - }) - ; + $dispatcher->getEventsManager()->attach( + 'dispatch:beforeDispatchLoop', + function () { + return true; + } + ); $dispatcher->dispatch(); @@ -135,7 +150,9 @@ public function testBeforeDispatchLoopBaselinePrePhalcon40MultipleReturnFalseMix 'afterDispatch', 'afterDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -159,23 +176,32 @@ public function testBeforeDispatchLoopBaselinePrePhalcon40MultipleReturnFalse(In { $dispatcher = $this->getDispatcher(); - $dispatcher->getEventsManager()->attach('dispatch:beforeDispatchLoop', function () { - return false; - }) - ; + $dispatcher->getEventsManager()->attach( + 'dispatch:beforeDispatchLoop', + function () { + return false; + } + ); + // Unfortunately, we really need to collect all responses or use the Event stopping property // instead of return false. The following statement breaks the ability to stop the chain. - $dispatcher->getEventsManager()->attach('dispatch:beforeDispatchLoop', function () { - return false; - }) - ; + $dispatcher->getEventsManager()->attach( + 'dispatch:beforeDispatchLoop', + function () { + return false; + } + ); $dispatcher->dispatch(); + + $expected = [ 'beforeDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -191,22 +217,31 @@ public function testBeforeDispatchLoopWithBeforeExceptionReturningFalse(Integrat { $dispatcher = $this->getDispatcher(); - $dispatcher->getEventsManager()->attach('dispatch:beforeDispatchLoop', function () { - throw new Exception('beforeDispatchLoop exception occurred'); - }) - ; - $dispatcher->getEventsManager()->attach('dispatch:beforeException', function () { - return false; - }) - ; + $dispatcher->getEventsManager()->attach( + 'dispatch:beforeDispatchLoop', + function () { + throw new Exception('beforeDispatchLoop exception occurred'); + } + ); + + $dispatcher->getEventsManager()->attach( + 'dispatch:beforeException', + function () { + return false; + } + ); $dispatcher->dispatch(); + + $expected = [ 'beforeDispatchLoop', 'beforeException: beforeDispatchLoop exception occurred', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } diff --git a/tests/integration/Mvc/Dispatcher/Refactor-DispatcherBeforeExecuteRouteCest.php b/tests/integration/Mvc/Dispatcher/Refactor-DispatcherBeforeExecuteRouteCest.php index afdc130f493..b398b1728c9 100644 --- a/tests/integration/Mvc/Dispatcher/Refactor-DispatcherBeforeExecuteRouteCest.php +++ b/tests/integration/Mvc/Dispatcher/Refactor-DispatcherBeforeExecuteRouteCest.php @@ -43,7 +43,12 @@ public function testBeforeExecuteRouteForwardOnce(IntegrationTester $I) 'dispatch:beforeExecuteRoute', function ($event, $dispatcher) use (&$forwarded) { if ($forwarded === false) { - $dispatcher->forward(['action' => 'index2']); + $dispatcher->forward( + [ + 'action' => 'index2', + ] + ); + $forwarded = true; } } @@ -67,7 +72,9 @@ function ($event, $dispatcher) use (&$forwarded) { 'afterDispatch', 'afterDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -85,11 +92,14 @@ public function testBeforeExecuteRouteReturnFalse(IntegrationTester $I) $dispatcher->getEventsManager()->attach( 'dispatch:beforeExecuteRoute', function () use ($dispatcherListener) { - $dispatcherListener->trace('beforeExecuteRoute: custom return false'); + $dispatcherListener->trace( + 'beforeExecuteRoute: custom return false' + ); + return false; } - ) - ; + ); + $dispatcher->dispatch(); $expected = [ @@ -99,7 +109,9 @@ function () use ($dispatcherListener) { 'beforeExecuteRoute: custom return false', 'afterDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -115,14 +127,19 @@ public function testBeforeExecuteRouteWithBeforeExceptionReturningFalse(Integrat { $dispatcher = $this->getDispatcher(); - $dispatcher->getEventsManager()->attach('dispatch:beforeExecuteRoute', function () { - throw new Exception('beforeExecuteRoute exception occurred'); - }) - ; - $dispatcher->getEventsManager()->attach('dispatch:beforeException', function () { - return false; - }) - ; + $dispatcher->getEventsManager()->attach( + 'dispatch:beforeExecuteRoute', + function () { + throw new Exception('beforeExecuteRoute exception occurred'); + } + ); + + $dispatcher->getEventsManager()->attach( + 'dispatch:beforeException', + function () { + return false; + } + ); $dispatcher->dispatch(); @@ -133,7 +150,9 @@ public function testBeforeExecuteRouteWithBeforeExceptionReturningFalse(Integrat 'beforeException: beforeExecuteRoute exception occurred', 'afterDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -150,20 +169,26 @@ public function testBeforeExecuteRouteWithBeforeExceptionBubble(IntegrationTeste $dispatcher = $this->getDispatcher(); $dispatcherListener = $this->getDispatcherListener(); - $dispatcher->getEventsManager()->attach('dispatch:beforeExecuteRoute', function () { - throw new Exception('beforeExecuteRoute exception occurred'); - }) - ; + $dispatcher->getEventsManager()->attach( + 'dispatch:beforeExecuteRoute', + function () { + throw new Exception('beforeExecuteRoute exception occurred'); + } + ); + $dispatcher->getEventsManager()->attach( 'dispatch:beforeException', function () use ($dispatcherListener) { - $dispatcherListener->trace('beforeException: custom before exception bubble'); + $dispatcherListener->trace( + 'beforeException: custom before exception bubble' + ); + return null; } - ) - ; + ); $caughtException = false; + try { $dispatcher->dispatch(); } catch (Exception $exception) { @@ -171,6 +196,7 @@ function () use ($dispatcherListener) { } $I->assertTrue($caughtException); + $expected = [ 'beforeDispatchLoop', 'beforeDispatch', @@ -178,7 +204,9 @@ function () use ($dispatcherListener) { 'beforeException: beforeExecuteRoute exception occurred', 'beforeException: custom before exception bubble', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -195,21 +223,31 @@ public function testBeforeExecuteRouteWithBeforeExceptionForwardOnce(Integration $dispatcher = $this->getDispatcher(); $dispatcherListener = $this->getDispatcherListener(); - $dispatcher->getEventsManager()->attach('dispatch:beforeExecuteRoute', function () use (&$forwarded) { - if ($forwarded === false) { - $forwarded = true; - throw new Exception('beforeExecuteRoute exception occurred'); + $dispatcher->getEventsManager()->attach( + 'dispatch:beforeExecuteRoute', + function () use (&$forwarded) { + if ($forwarded === false) { + $forwarded = true; + + throw new Exception('beforeExecuteRoute exception occurred'); + } } - }) - ; + ); + $dispatcher->getEventsManager()->attach( 'dispatch:beforeException', function ($event, $dispatcher) use ($dispatcherListener) { - $dispatcherListener->trace('beforeException: custom before exception forward'); - $dispatcher->forward(['action' => 'index2']); + $dispatcherListener->trace( + 'beforeException: custom before exception forward' + ); + + $dispatcher->forward( + [ + 'action' => 'index2', + ] + ); } - ) - ; + ); $dispatcher->dispatch(); @@ -230,7 +268,9 @@ function ($event, $dispatcher) use ($dispatcherListener) { 'afterDispatch', 'afterDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Mvc/Dispatcher/Refactor-DispatcherBeforeExecuteRouteMethodCest.php b/tests/integration/Mvc/Dispatcher/Refactor-DispatcherBeforeExecuteRouteMethodCest.php index 09c6784ee25..5b888aa41d1 100644 --- a/tests/integration/Mvc/Dispatcher/Refactor-DispatcherBeforeExecuteRouteMethodCest.php +++ b/tests/integration/Mvc/Dispatcher/Refactor-DispatcherBeforeExecuteRouteMethodCest.php @@ -37,7 +37,11 @@ class DispatcherBeforeExecuteRouteMethodCest extends BaseDispatcher public function testBeforeExecuteRouteForwardOnce(IntegrationTester $I) { $dispatcher = $this->getDispatcher(); - $dispatcher->setControllerName('dispatcher-test-before-execute-route-forward'); + + $dispatcher->setControllerName( + 'dispatcher-test-before-execute-route-forward' + ); + $dispatcher->dispatch(); $expected = [ @@ -56,7 +60,9 @@ public function testBeforeExecuteRouteForwardOnce(IntegrationTester $I) 'afterDispatch', 'afterDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -69,7 +75,11 @@ public function testBeforeExecuteRouteForwardOnce(IntegrationTester $I) public function testBeforeExecuteRouteReturnFalse(IntegrationTester $I) { $dispatcher = $this->getDispatcher(); - $dispatcher->setControllerName('dispatcher-test-before-execute-route-return-false'); + + $dispatcher->setControllerName( + 'dispatcher-test-before-execute-route-return-false' + ); + $dispatcher->dispatch(); $expected = [ @@ -79,7 +89,9 @@ public function testBeforeExecuteRouteReturnFalse(IntegrationTester $I) 'beforeExecuteRoute-method', 'afterDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -94,12 +106,17 @@ public function testBeforeExecuteRouteReturnFalse(IntegrationTester $I) public function testBeforeExecuteRouteWithBeforeExceptionReturningFalse(IntegrationTester $I) { $dispatcher = $this->getDispatcher(); - $dispatcher->setControllerName('dispatcher-test-before-execute-route-exception'); - $dispatcher->getEventsManager()->attach('dispatch:beforeException', function () { - return false; - }) - ; + $dispatcher->setControllerName( + 'dispatcher-test-before-execute-route-exception' + ); + + $dispatcher->getEventsManager()->attach( + 'dispatch:beforeException', + function () { + return false; + } + ); $dispatcher->dispatch(); @@ -111,7 +128,9 @@ public function testBeforeExecuteRouteWithBeforeExceptionReturningFalse(Integrat 'beforeException: beforeExecuteRoute exception occurred', 'afterDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -127,18 +146,24 @@ public function testBeforeExecuteRouteWithBeforeExceptionBubble(IntegrationTeste { $dispatcher = $this->getDispatcher(); $dispatcherListener = $this->getDispatcherListener(); - $dispatcher->setControllerName('dispatcher-test-before-execute-route-exception'); + + $dispatcher->setControllerName( + 'dispatcher-test-before-execute-route-exception' + ); $dispatcher->getEventsManager()->attach( 'dispatch:beforeException', function () use ($dispatcherListener) { - $dispatcherListener->trace('beforeException: custom before exception bubble'); + $dispatcherListener->trace( + 'beforeException: custom before exception bubble' + ); + return null; } - ) - ; + ); $caughtException = false; + try { $dispatcher->dispatch(); } catch (Exception $exception) { @@ -146,6 +171,7 @@ function () use ($dispatcherListener) { } $I->assertTrue($caughtException); + $expected = [ 'beforeDispatchLoop', 'beforeDispatch', @@ -154,7 +180,9 @@ function () use ($dispatcherListener) { 'beforeException: beforeExecuteRoute exception occurred', 'beforeException: custom before exception bubble', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -169,19 +197,26 @@ public function testBeforeExecuteRouteWithBeforeExceptionForward(IntegrationTest { $dispatcher = $this->getDispatcher(); $dispatcherListener = $this->getDispatcherListener(); - $dispatcher->setControllerName('dispatcher-test-before-execute-route-exception'); + + $dispatcher->setControllerName( + 'dispatcher-test-before-execute-route-exception' + ); $dispatcher->getEventsManager()->attach( 'dispatch:beforeException', function ($event, $dispatcher) use ($dispatcherListener) { - $dispatcherListener->trace('beforeException: custom before exception forward'); - $dispatcher->forward([ - 'controller' => 'dispatcher-test-default', - 'action' => 'index', - ]); + $dispatcherListener->trace( + 'beforeException: custom before exception forward' + ); + + $dispatcher->forward( + [ + 'controller' => 'dispatcher-test-default', + 'action' => 'index', + ] + ); } - ) - ; + ); $dispatcher->dispatch(); @@ -203,7 +238,9 @@ function ($event, $dispatcher) use ($dispatcherListener) { 'afterDispatch', 'afterDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Mvc/Dispatcher/Refactor-DispatcherInitializeMethodCest.php b/tests/integration/Mvc/Dispatcher/Refactor-DispatcherInitializeMethodCest.php index 74223cb31eb..37046ed2bba 100644 --- a/tests/integration/Mvc/Dispatcher/Refactor-DispatcherInitializeMethodCest.php +++ b/tests/integration/Mvc/Dispatcher/Refactor-DispatcherInitializeMethodCest.php @@ -37,9 +37,11 @@ class DispatcherInitializeMethodCest extends BaseDispatcher public function testInitializeForward(IntegrationTester $I) { $dispatcher = $this->getDispatcher(); + $dispatcher->setControllerName('dispatcher-test-initialize-forward'); $caughtException = false; + try { $dispatcher->dispatch(); } catch (Exception $exception) { @@ -47,6 +49,7 @@ public function testInitializeForward(IntegrationTester $I) } $I->assertTrue($caughtException); + $expected = [ 'beforeDispatchLoop', 'beforeDispatch', @@ -55,7 +58,9 @@ public function testInitializeForward(IntegrationTester $I) 'initialize-method', 'beforeException: Forwarding inside a controller\'s initialize() method is forbidden', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -68,7 +73,9 @@ public function testInitializeForward(IntegrationTester $I) public function testInitializeReturnFalse(IntegrationTester $I) { $dispatcher = $this->getDispatcher(); + $dispatcher->setControllerName('dispatcher-test-initialize-return-false'); + $dispatcher->dispatch(); $expected = [ @@ -84,7 +91,9 @@ public function testInitializeReturnFalse(IntegrationTester $I) 'afterDispatch', 'afterDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -99,6 +108,7 @@ public function testInitializeReturnFalse(IntegrationTester $I) public function testInitializeWithBeforeExceptionReturningFalse(IntegrationTester $I) { $dispatcher = $this->getDispatcher(); + $dispatcher->setControllerName('dispatcher-test-initialize-exception'); $dispatcher->getEventsManager()->attach('dispatch:beforeException', function () { @@ -118,7 +128,9 @@ public function testInitializeWithBeforeExceptionReturningFalse(IntegrationTeste 'beforeException: initialize exception occurred', 'afterDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } @@ -134,17 +146,20 @@ public function testInitializeWithBeforeExceptionBubble(IntegrationTester $I) { $dispatcher = $this->getDispatcher(); $dispatcherListener = $this->getDispatcherListener(); + $dispatcher->setControllerName('dispatcher-test-initialize-exception'); $dispatcher->getEventsManager()->attach( 'dispatch:beforeException', function () use ($dispatcherListener) { // Returning anything other then false should bubble the exception. - $dispatcherListener->trace('beforeException: custom before exception bubble'); + $dispatcherListener->trace( + 'beforeException: custom before exception bubble' + ); + return null; } - ) - ; + ); $caughtException = false; try { @@ -213,7 +228,9 @@ function ($event, $dispatcher) use ($dispatcherListener) { 'afterDispatch', 'afterDispatchLoop', ]; - $actual = $this->getDispatcherListener()->getTrace(); + + $actual = $this->getDispatcherListener()->getTrace(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Mvc/Dispatcher/Refactor-ForwardCest.php b/tests/integration/Mvc/Dispatcher/Refactor-ForwardCest.php index 96bedd27ac8..c3f4602b1cd 100644 --- a/tests/integration/Mvc/Dispatcher/Refactor-ForwardCest.php +++ b/tests/integration/Mvc/Dispatcher/Refactor-ForwardCest.php @@ -35,35 +35,57 @@ class RefactorForwardCest public function handlingException(IntegrationTester $I) { $di = new FactoryDefault(); - $di->set('view', function () { - $view = new View(); - $view->setViewsDir(dataFolder('fixtures/views/')); - return $view; - }, true); + $di->set( + 'view', + function () { + $view = new View(); + + $view->setViewsDir( + dataFolder('fixtures/views/') + ); + + return $view; + }, + true + ); $eventsManager = new Manager(); - $eventsManager->attach('dispatch:beforeException', function ($event, $dispatcher, $exception) { - $dispatcher->forward([ - 'controller' => 'exception', - 'action' => 'second', - ]); + $eventsManager->attach( + 'dispatch:beforeException', + function ($event, $dispatcher, $exception) { + $dispatcher->forward( + [ + 'controller' => 'exception', + 'action' => 'second', + ] + ); - // Prevent the exception from bubbling - return false; - }); + // Prevent the exception from bubbling + return false; + } + ); $dispatcher = new Dispatcher(); + $dispatcher->setEventsManager($eventsManager); $di->setShared('dispatcher', $dispatcher); $application = new Application(); - $application->setEventsManager(new Manager()); + + $application->setEventsManager( + new Manager() + ); + $application->setDI($di); $response = $application->handle("/exception"); - $I->assertSame("I should be displayed", $response->getContent()); + + $I->assertSame( + "I should be displayed", + $response->getContent() + ); } } diff --git a/tests/integration/Mvc/Model/Refactor-CriteriaCest.php b/tests/integration/Mvc/Model/Refactor-CriteriaCest.php index beeda3c7b2c..07d74137dc7 100644 --- a/tests/integration/Mvc/Model/Refactor-CriteriaCest.php +++ b/tests/integration/Mvc/Model/Refactor-CriteriaCest.php @@ -41,10 +41,20 @@ public function _before(IntegrationTester $I) */ public function shouldExecuteInWhereQueryWithEmptyArray(IntegrationTester $I) { - $criteria = Users::query()->inWhere(Users::class . '.id', []); - - $I->assertEquals(Users::class . '.id != ' . Users::class . '.id', $criteria->getWhere()); - $I->assertInstanceOf(Simple::class, $criteria->execute()); + $criteria = Users::query()->inWhere( + Users::class . '.id', + [] + ); + + $I->assertEquals( + Users::class . '.id != ' . Users::class . '.id', + $criteria->getWhere() + ); + + $I->assertInstanceOf( + Simple::class, + $criteria->execute() + ); } /** @@ -57,17 +67,23 @@ public function shouldExecuteInWhereQueryWithEmptyArray(IntegrationTester $I) public function shouldCorrectHandleLimitAndOffset(IntegrationTester $I) { $I->skipTest('TODO - Check the test data'); + $examples = $this->getLimitOffset(); + foreach ($examples as $item) { $limit = $item[0]; $offset = $item[1]; $expected = $item[2]; + /** @var \Phalcon\Mvc\Model\Criteria $query */ $query = Users::query(); + $query->limit($limit, $offset); - $actual = $query->getLimit(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $query->getLimit() + ); } } @@ -96,15 +112,26 @@ private function getLimitOffset(): array public function createBuilderFromCriteria(IntegrationTester $I) { $criteria = Robots::query()->where("type='mechanical'"); - $I->assertInstanceOf(Builder::class, $criteria->createBuilder()); + + $I->assertInstanceOf( + Builder::class, + $criteria->createBuilder() + ); } public function havingNotOverwritingGroupBy(IntegrationTester $I) { $query = Personas::query()->groupBy('estado')->having('SUM(cupo) > 1000000'); - $I->assertEquals('estado', $query->getGroupBy()); - $I->assertEquals('SUM(cupo) > 1000000', $query->getHaving()); + $I->assertEquals( + 'estado', + $query->getGroupBy() + ); + + $I->assertEquals( + 'SUM(cupo) > 1000000', + $query->getHaving() + ); } /** @@ -115,13 +142,23 @@ public function havingNotOverwritingGroupBy(IntegrationTester $I) */ public function where(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); + $this->container->setShared( + 'db', + $example['adapter'] + ); $personas = Personas::query()->where("estado='I'")->execute(); $people = People::find("estado='I'"); - $I->assertEquals(count($personas->toArray()), count($people->toArray())); - $I->assertInstanceOf(Simple::class, $personas); + $I->assertEquals( + count($personas->toArray()), + count($people->toArray()) + ); + + $I->assertInstanceOf( + Simple::class, + $personas + ); } /** @@ -132,9 +169,15 @@ public function where(IntegrationTester $I, Example $example) */ public function whereRenamed(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); - - $I->assertInstanceOf(Simple::class, Personers::query()->where("status='I'")->execute()); + $this->container->setShared( + 'db', + $example['adapter'] + ); + + $I->assertInstanceOf( + Simple::class, + Personers::query()->where("status='I'")->execute() + ); } /** @@ -145,12 +188,18 @@ public function whereRenamed(IntegrationTester $I, Example $example) */ public function conditions(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); + $this->container->setShared( + 'db', + $example['adapter'] + ); $personas = Personas::query()->conditions("estado='I'")->execute(); $people = People::find("estado='I'"); - $I->assertEquals(count($personas->toArray()), count($people->toArray())); + $I->assertEquals( + count($personas->toArray()), + count($people->toArray()) + ); } /** @@ -161,9 +210,15 @@ public function conditions(IntegrationTester $I, Example $example) */ public function conditionsRenamed(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); - - $I->assertInstanceOf(Simple::class, Personers::query()->conditions("status='I'")->execute()); + $this->container->setShared( + 'db', + $example['adapter'] + ); + + $I->assertInstanceOf( + Simple::class, + Personers::query()->conditions("status='I'")->execute() + ); } /** @@ -174,7 +229,10 @@ public function conditionsRenamed(IntegrationTester $I, Example $example) */ public function whereOrderBy(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); + $this->container->setShared( + 'db', + $example['adapter'] + ); $personas = Personas::query() ->where("estado='A'") @@ -182,10 +240,22 @@ public function whereOrderBy(IntegrationTester $I, Example $example) ->execute() ; - $people = People::find(["estado='A'", "order" => "nombres"]); - - $I->assertEquals(count($personas->toArray()), count($people->toArray())); - $I->assertEquals($personas->getFirst()->cedula, $people->getFirst()->cedula); + $people = People::find( + [ + "estado='A'", + "order" => "nombres", + ] + ); + + $I->assertEquals( + count($personas->toArray()), + count($people->toArray()) + ); + + $I->assertEquals( + $personas->getFirst()->cedula, + $people->getFirst()->cedula + ); } /** @@ -196,7 +266,10 @@ public function whereOrderBy(IntegrationTester $I, Example $example) */ public function whereOrderByRenamed(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); + $this->container->setShared( + 'db', + $example['adapter'] + ); $personers = Personers::query() ->where("status='A'") @@ -204,8 +277,15 @@ public function whereOrderByRenamed(IntegrationTester $I, Example $example) ->execute() ; - $I->assertInstanceOf(Simple::class, $personers); - $I->assertInstanceOf(Personers::class, $personers->getFirst()); + $I->assertInstanceOf( + Simple::class, + $personers + ); + + $I->assertInstanceOf( + Personers::class, + $personers->getFirst() + ); } /** @@ -216,7 +296,10 @@ public function whereOrderByRenamed(IntegrationTester $I, Example $example) */ public function whereOrderByLimit(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); + $this->container->setShared( + 'db', + $example['adapter'] + ); $personas = Personas::query() ->where("estado='A'") @@ -225,14 +308,23 @@ public function whereOrderByLimit(IntegrationTester $I, Example $example) ->execute() ; - $people = People::find([ - "estado='A'", - "order" => "nombres", - "limit" => 100, - ]); - - $I->assertEquals(count($personas->toArray()), count($people->toArray())); - $I->assertEquals($personas->getFirst()->cedula, $people->getFirst()->cedula); + $people = People::find( + [ + "estado='A'", + "order" => "nombres", + "limit" => 100, + ] + ); + + $I->assertEquals( + count($personas->toArray()), + count($people->toArray()) + ); + + $I->assertEquals( + $personas->getFirst()->cedula, + $people->getFirst()->cedula + ); } /** @@ -243,7 +335,10 @@ public function whereOrderByLimit(IntegrationTester $I, Example $example) */ public function whereOrderByLimitRenamed(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); + $this->container->setShared( + 'db', + $example['adapter'] + ); $personers = Personers::query() ->where("status='A'") @@ -252,8 +347,15 @@ public function whereOrderByLimitRenamed(IntegrationTester $I, Example $example) ->execute() ; - $I->assertInstanceOf(Simple::class, $personers); - $I->assertInstanceOf(Personers::class, $personers->getFirst()); + $I->assertInstanceOf( + Simple::class, + $personers + ); + + $I->assertInstanceOf( + Personers::class, + $personers->getFirst() + ); } /** @@ -264,7 +366,10 @@ public function whereOrderByLimitRenamed(IntegrationTester $I, Example $example) */ public function bindParamsWithLimit(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); + $this->container->setShared( + 'db', + $example['adapter'] + ); $personas = Personas::query() ->where("estado=?1") @@ -274,15 +379,26 @@ public function bindParamsWithLimit(IntegrationTester $I, Example $example) ->execute() ; - $people = People::find([ - "estado=?1", - "bind" => [1 => "A"], - "order" => "nombres", - "limit" => 100, - ]); - - $I->assertEquals(count($personas->toArray()), count($people->toArray())); - $I->assertEquals($personas->getFirst()->cedula, $people->getFirst()->cedula); + $people = People::find( + [ + "estado=?1", + "bind" => [ + 1 => "A", + ], + "order" => "nombres", + "limit" => 100, + ] + ); + + $I->assertEquals( + count($personas->toArray()), + count($people->toArray()) + ); + + $I->assertEquals( + $personas->getFirst()->cedula, + $people->getFirst()->cedula + ); } /** @@ -293,7 +409,10 @@ public function bindParamsWithLimit(IntegrationTester $I, Example $example) */ public function bindParamsWithOrderAndLimitRenamed(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); + $this->container->setShared( + 'db', + $example['adapter'] + ); $personers = Personers::query() ->where("status=?1") @@ -303,8 +422,15 @@ public function bindParamsWithOrderAndLimitRenamed(IntegrationTester $I, Example ->execute() ; - $I->assertInstanceOf(Simple::class, $personers); - $I->assertInstanceOf(Personers::class, $personers->getFirst()); + $I->assertInstanceOf( + Simple::class, + $personers + ); + + $I->assertInstanceOf( + Personers::class, + $personers->getFirst() + ); } /** @@ -315,7 +441,10 @@ public function bindParamsWithOrderAndLimitRenamed(IntegrationTester $I, Example */ public function bindParamsAsPlaceholdersWithOrderAndLimitRenamed(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); + $this->container->setShared( + 'db', + $example['adapter'] + ); $personers = Personers::query() ->where("status=:status:") @@ -325,8 +454,15 @@ public function bindParamsAsPlaceholdersWithOrderAndLimitRenamed(IntegrationTest ->execute() ; - $I->assertInstanceOf(Simple::class, $personers); - $I->assertInstanceOf(Personers::class, $personers->getFirst()); + $I->assertInstanceOf( + Simple::class, + $personers + ); + + $I->assertInstanceOf( + Personers::class, + $personers->getFirst() + ); } /** @@ -337,7 +473,10 @@ public function bindParamsAsPlaceholdersWithOrderAndLimitRenamed(IntegrationTest */ public function limitWithOffset(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); + $this->container->setShared( + 'db', + $example['adapter'] + ); $personas = Personas::query() ->where("estado=?1") @@ -347,15 +486,29 @@ public function limitWithOffset(IntegrationTester $I, Example $example) ->execute() ; - $people = People::find([ - "estado=?1", - "bind" => [1 => "A"], - "order" => "nombres", - "limit" => ['number' => 100, 'offset' => 10], - ]); - - $I->assertEquals(count($personas->toArray()), count($people->toArray())); - $I->assertEquals($personas->getFirst()->cedula, $people->getFirst()->cedula); + $people = People::find( + [ + "estado=?1", + "bind" => [ + 1 => "A", + ], + "order" => "nombres", + "limit" => [ + 'number' => 100, + 'offset' => 10, + ], + ] + ); + + $I->assertEquals( + count($personas->toArray()), + count($people->toArray()) + ); + + $I->assertEquals( + $personas->getFirst()->cedula, + $people->getFirst()->cedula + ); } /** @@ -366,7 +519,10 @@ public function limitWithOffset(IntegrationTester $I, Example $example) */ public function bindOrderLimit(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); + $this->container->setShared( + 'db', + $example['adapter'] + ); $personas = Personas::query() ->where("estado=:estado:") @@ -376,15 +532,26 @@ public function bindOrderLimit(IntegrationTester $I, Example $example) ->execute() ; - $people = People::find([ - "estado=:estado:", - "bind" => ["estado" => "A"], - "order" => "nombres", - "limit" => 100, - ]); - - $I->assertEquals(count($personas->toArray()), count($people->toArray())); - $I->assertEquals($personas->getFirst()->cedula, $people->getFirst()->cedula); + $people = People::find( + [ + "estado=:estado:", + "bind" => [ + "estado" => "A", + ], + "order" => "nombres", + "limit" => 100, + ] + ); + + $I->assertEquals( + count($personas->toArray()), + count($people->toArray()) + ); + + $I->assertEquals( + $personas->getFirst()->cedula, + $people->getFirst()->cedula + ); } /** @@ -395,11 +562,17 @@ public function bindOrderLimit(IntegrationTester $I, Example $example) */ public function orderBy(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); + $this->container->setShared( + 'db', + $example['adapter'] + ); $personas = Personas::query()->orderBy("nombres"); - $I->assertEquals($personas->getOrderBy(), "nombres"); + $I->assertEquals( + "nombres", + $personas->getOrderBy() + ); } /** @@ -411,7 +584,11 @@ public function orderBy(IntegrationTester $I, Example $example) */ public function freshCache(IntegrationTester $I, Example $example) { - $this->container->setShared('db', $example['adapter']); + $this->container->setShared( + 'db', + $example['adapter'] + ); + $this->getAndSetModelsCacheFile(); $personas = Personas::query() @@ -420,7 +597,9 @@ public function freshCache(IntegrationTester $I, Example $example) ->execute() ; - $I->assertTrue($personas->isFresh()); + $I->assertTrue( + $personas->isFresh() + ); $personas = Personas::query() ->where("estado='I'") @@ -428,9 +607,14 @@ public function freshCache(IntegrationTester $I, Example $example) ->execute() ; - $I->assertFalse($personas->isFresh()); + $I->assertFalse( + $personas->isFresh() + ); + + $I->amInPath( + cacheFolder() + ); - $I->amInPath(cacheFolder()); $I->safeDeleteFile('cache-for-issue-2131'); $I->dontSeeFileFound('cache-for-issue-2131'); } @@ -440,7 +624,7 @@ public function freshCache(IntegrationTester $I, Example $example) * * @return array */ - protected function adapterProvider() + protected function adapterProvider(): array { return [ [ diff --git a/tests/integration/Mvc/Refactor-RouterCest.php b/tests/integration/Mvc/Refactor-RouterCest.php index f9a88919e48..0fc27eef859 100644 --- a/tests/integration/Mvc/Refactor-RouterCest.php +++ b/tests/integration/Mvc/Refactor-RouterCest.php @@ -11,6 +11,7 @@ namespace Phalcon\Test\Integration\Mvc; +use Codeception\Example; use IntegrationTester; use Phalcon\Mvc\Router; use Phalcon\Mvc\Router\Route; @@ -25,27 +26,26 @@ class RouterCest * * @author Andy Gutierrez * @since 2012-12-25 + * + * @dataProvider getMatchingWithConverted */ - public function testUsingRouteConverters(IntegrationTester $I) + public function testUsingRouteConverters(IntegrationTester $I, Example $example) { - $examples = $this->getMatchingWithConverted(); - foreach ($examples as $item) { - $route = $item[0]; - $params = $item[1]; + $route = $example[0]; + $params = $example[1]; - $router = $this->getRouterAndSetData(); - $router->handle($route); + $router = $this->getRouterAndSetData(); + $router->handle($route); - $actual = $router->wasMatched(); - $I->assertTrue($actual); + $actual = $router->wasMatched(); + $I->assertTrue($actual); - $expected = $params['controller']; - $actual = $router->getControllerName(); - $I->assertEquals($expected, $actual); - $expected = $params['action']; - $actual = $router->getActionName(); - $I->assertEquals($expected, $actual); - } + $expected = $params['controller']; + $actual = $router->getControllerName(); + $I->assertEquals($expected, $actual); + $expected = $params['action']; + $actual = $router->getActionName(); + $I->assertEquals($expected, $actual); } private function getMatchingWithConverted(): array @@ -59,6 +59,7 @@ private function getMatchingWithConverted(): array 'params' => ['this-is-a-country'], ], ], + [ '/BINARY/1101', [ @@ -83,31 +84,51 @@ public function testUsingCallbacksBeforeMatchRoute(IntegrationTester $I) $router ->add('/static/route') - ->beforeMatch(function () use (&$trace) { - $trace++; - return false; - }) + ->beforeMatch( + function () use (&$trace) { + $trace++; + + return false; + } + ) ; $router ->add('/static/route2') - ->beforeMatch(function () use (&$trace) { - $trace++; - return true; - }) + ->beforeMatch( + function () use (&$trace) { + $trace++; + + return true; + } + ) ; + + $router->handle("/"); - $actual = $router->wasMatched(); - $I->assertFalse($actual); + + $I->assertFalse( + $router->wasMatched() + ); + + $router->handle('/static/route'); - $actual = $router->wasMatched(); - $I->assertFalse($actual); + + $I->assertFalse( + $router->wasMatched() + ); + + $router->handle('/static/route2'); - $actual = $router->wasMatched(); - $I->assertTrue($actual); + + $I->assertTrue( + $router->wasMatched() + ); + + $I->assertEquals(2, $trace); } @@ -121,6 +142,7 @@ public function testUsingCallbacksBeforeMatchRoute(IntegrationTester $I) public function testGettingNamedRoutes(IntegrationTester $I) { $I->skipTest('TODO - Check the getRouteById'); + $router = $this->getRouter(false); $usersFind = $router->add('/api/users/find')->setHttpMethods('GET')->setName('usersFind'); $usersAdd = $router->add('/api/users/add')->setHttpMethods('POST')->setName('usersAdd'); @@ -149,19 +171,28 @@ public function shouldMatchWithRouter(IntegrationTester $I) { $pathToRouterData = $this->getDataRouter(); $examples = $this->getMatchingWithRouter(); + foreach ($examples as $params) { $router = $this->getRouterAndSetRoutes($pathToRouterData); - $router->handle($params['uri']); - - $expected = $params['controller']; - $actual = $router->getControllerName(); - $I->assertEquals($expected, $actual); - $expected = $params['action']; - $actual = $router->getActionName(); - $I->assertEquals($expected, $actual); - $expected = $params['params']; - $actual = $router->getParams(); - $I->assertEquals($expected, $actual); + + $router->handle( + $params['uri'] + ); + + $I->assertEquals( + $params['controller'], + $router->getControllerName() + ); + + $I->assertEquals( + $params['action'], + $router->getActionName() + ); + + $I->assertEquals( + $params['params'], + $router->getParams() + ); } } @@ -383,20 +414,30 @@ public function shouldMatchWithTheRouterByUsingHttpMethods(IntegrationTester $I) { $pathToRouterData = $this->getDataRouterHttp(); $examples = $this->getMatchingWithRouterHttp(); + foreach ($examples as $params) { - $router = $this->getRouterAndSetRoutes($pathToRouterData); + $router = $this->getRouterAndSetRoutes($pathToRouterData); + $_SERVER['REQUEST_METHOD'] = $params['method']; - $router->handle($params['uri']); - - $expected = $params['controller']; - $actual = $router->getControllerName(); - $I->assertEquals($expected, $actual); - $expected = $params['action']; - $actual = $router->getActionName(); - $I->assertEquals($expected, $actual); - $expected = $params['params']; - $actual = $router->getParams(); - $I->assertEquals($expected, $actual); + + $router->handle( + $params['uri'] + ); + + $I->assertEquals( + $params['controller'], + $router->getControllerName() + ); + + $I->assertEquals( + $params['action'], + $router->getActionName() + ); + + $I->assertEquals( + $params['params'], + $router->getParams() + ); } } @@ -509,19 +550,28 @@ public function shouldMatchWithGotRouterParam(IntegrationTester $I) { $pathToRouterData = $this->getDataToRouter(); $examples = $this->getMatchingWithToRouter(); + foreach ($examples as $params) { $router = $this->getRouterAndSetRoutes($pathToRouterData); - $router->handle($params['uri']); - - $expected = $params['controller']; - $actual = $router->getControllerName(); - $I->assertEquals($expected, $actual); - $expected = $params['action']; - $actual = $router->getActionName(); - $I->assertEquals($expected, $actual); - $expected = $params['params']; - $actual = $router->getParams(); - $I->assertEquals($expected, $actual); + + $router->handle( + $params['uri'] + ); + + $I->assertEquals( + $params['controller'], + $router->getControllerName() + ); + + $I->assertEquals( + $params['action'], + $router->getActionName() + ); + + $I->assertEquals( + $params['params'], + $router->getParams() + ); } } @@ -572,20 +622,23 @@ private function getMatchingWithToRouter(): array * * @author Andy Gutierrez * @since 2012-01-16 + * + * @dataProvider getMatchingWithPathProvider */ - public function testAddingRouteByUsingShortPaths(IntegrationTester $I) + public function testAddingRouteByUsingShortPaths(IntegrationTester $I, Example $example) { - $examples = $this->getMatchingWithPathProvider(); - foreach ($examples as $item) { - $route = $item[0]; - $path = $item[1]; - $expected = $item[2]; - $router = $this->getRouter(false); - $route = $router->add($route, $path); - - $actual = $route->getPaths(); - $I->assertEquals($expected, $actual); - } + $route = $example[0]; + $path = $example[1]; + $expected = $example[2]; + + $router = $this->getRouter(false); + + $route = $router->add($route, $path); + + $I->assertEquals( + $expected, + $route->getPaths() + ); } private function getMatchingWithPathProvider(): array @@ -665,17 +718,25 @@ public function shouldMathWithHostnameRegex(IntegrationTester $I) // $pathToRouterData = $this->getDataRouterHostName(); $pathToRouterData = $this->getDataToHostnameRegex(); $examples = $this->getMatchingWithHostnameRegex(); + foreach ($examples as $item) { $expected = $item[0]; $handle = $item[1]; $hostname = $item[2]; - $router = $this->getRouterAndSetRoutesAndHostNames($pathToRouterData, false); + + $router = $this->getRouterAndSetRoutesAndHostNames( + $pathToRouterData, + false + ); $_SERVER['HTTP_HOST'] = $hostname; + $router->handle($handle); - $actual = $router->getControllerName(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $router->getControllerName() + ); } } @@ -742,18 +803,29 @@ private function getMatchingWithHostnameRegex(): array public function shouldMathWithHostnameRegexWithHostPort111(IntegrationTester $I) { $I->skipTest('TODO - Check'); + $pathToRouterData = $this->getDataRegexRouterHostPort(); $examples = $this->getMatchingWithRegexRouterHostPort(); + foreach ($examples as $item) { $param = $item[0]; $expected = $item[1]; - $router = $this->getRouterAndSetRoutesAndHostNames($pathToRouterData, false); + $router = $this->getRouterAndSetRoutesAndHostNames( + $pathToRouterData, + false + ); + $_SERVER['HTTP_HOST'] = $param['hostname'] . ($param['port'] ? ':' . $param['port'] : ''); - $router->handle($param['handle']); - $actual = $router->getControllerName(); - $I->assertEquals($expected, $actual); + $router->handle( + $param['handle'] + ); + + $I->assertEquals( + $expected, + $router->getControllerName() + ); } } @@ -871,15 +943,26 @@ public function shouldReturnCorrectController(IntegrationTester $I) { $pathToRouterData = $this->getDataRouterHostName(); $examples = $this->getMatchingWithHostName(); + foreach ($examples as $item) { - $param = $item[0]; - $expected = $item[1]; - $router = $this->getRouterAndSetRoutesAndHostNames($pathToRouterData, false); + $param = $item[0]; + $expected = $item[1]; + + $router = $this->getRouterAndSetRoutesAndHostNames( + $pathToRouterData, + false + ); + $_SERVER['HTTP_HOST'] = $param['hostname']; - $router->handle($param['handle']); - $actual = $router->getControllerName(); - $I->assertEquals($expected, $actual); + $router->handle( + $param['handle'] + ); + + $I->assertEquals( + $expected, + $router->getControllerName() + ); } } diff --git a/tests/integration/Mvc/Refactor-UrlCest.php b/tests/integration/Mvc/Refactor-UrlCest.php index f9986573a8d..78b0541d9e5 100644 --- a/tests/integration/Mvc/Refactor-UrlCest.php +++ b/tests/integration/Mvc/Refactor-UrlCest.php @@ -11,6 +11,7 @@ namespace Phalcon\Test\Integration\Mvc; +use Codeception\Example; use IntegrationTester; use Phalcon\Mvc\Router; use Phalcon\Test\Fixtures\Traits\DiTrait; @@ -39,9 +40,11 @@ private function setupRoutes() $container = $this->getDi(); $router = new Router(false); $routerData = $this->getDataToSetDi(); + foreach ($routerData as $data) { $this->getRouteAndSetRouteMethod($router, $data)->setName($data['setname']); } + $router->removeExtraSlashes(true); $container->set('router', $router); @@ -102,20 +105,25 @@ private function getDataToSetDi(): array * * @author Nikolaos Dimopoulos * @since 2014-09-04 + * + * @dataProvider getUrlToSetServer */ - public function shouldGetCorrectUrlWithServer(IntegrationTester $I) + public function shouldGetCorrectUrlWithServer(IntegrationTester $I, Example $example) { - $examples = $this->getUrlToSetServer(); - foreach ($examples as $item) { - $params = $item[0]; - $expected = $item[1]; + $params = $example['params']; - $_SERVER['PHP_SELF'] = $params['server_php_self']; + $_SERVER['PHP_SELF'] = $params['server_php_self']; - $url = $this->getService('url'); - $actual = $url->get($params['get']); - $I->assertEquals($expected, $actual); - } + $url = $this->getService('url'); + + $actual = $url->get( + $params['get'] + ); + + $I->assertEquals( + $example['expected'], + $actual + ); } private function getUrlToSetServer(): array @@ -123,19 +131,20 @@ private function getUrlToSetServer(): array return [ //Tests the base url [ - [ + 'params' => [ 'server_php_self' => '/index.php', 'get' => null, ], - '/', + 'expected' => '/', ], + //Tests a different url [ - [ + 'params' => [ 'server_php_self' => '/index.php', 'get' => 'classes/api/Some', ], - '/classes/api/Some', + 'expected' => '/classes/api/Some', ], ]; } @@ -145,20 +154,25 @@ private function getUrlToSetServer(): array * * @author Nikolaos Dimopoulos * @since 2014-09-04 + * + * @dataProvider getUrlToSetBaseUri */ - public function shouldCorrectSetBaseUri(IntegrationTester $I)//+ + public function shouldCorrectSetBaseUri(IntegrationTester $I, Example $example) { - $examples = $this->getUrlToSetBaseUri(); - foreach ($examples as $item) { - $params = $item[0]; - $expected = $item[1]; + $params = $example[0]; + $expected = $example[1]; - $url = $this->getService('url'); - $url->setBaseUri($params['base_url']); + $url = $this->getService('url'); - $actual = $url->get($params['param']); - $I->assertEquals($expected, $actual); - } + $url->setBaseUri( + $params['base_url'] + ); + + $actual = $url->get( + $params['param'] + ); + + $I->assertEquals($expected, $actual); } private function getUrlToSetBaseUri(): array @@ -176,6 +190,7 @@ private function getUrlToSetBaseUri(): array ], '/admin/products/p/index', ], + //Tests the url with a controller [ [ @@ -232,20 +247,25 @@ private function getUrlToSetBaseUri(): array * @author Olivier Monaco * @since 2015-02-03 * @issue https://github.com/phalcon/cphalcon/issues/3315 + * + * @dataProvider getUrlToSetWithoutDi */ - public function shouldGetCorrectUrl(IntegrationTester $I) + public function shouldGetCorrectUrl(IntegrationTester $I, Example $example) { - $examples = $this->getUrlToSetWithoutDi(); - foreach ($examples as $item) { - $params = $item[0]; - $expected = $item[1]; + $params = $example[0]; + $expected = $example[1]; - $url = $this->getService('url'); - $url->setBaseUri($params['base_url']); + $url = $this->getService('url'); - $actual = $url->get($params['get']); - $I->assertEquals($expected, $actual); - } + $url->setBaseUri( + $params['base_url'] + ); + + $actual = $url->get( + $params['get'] + ); + + $I->assertEquals($expected, $actual); } private function getUrlToSetWithoutDi(): array @@ -310,20 +330,26 @@ private function getUrlToSetWithoutDi(): array * @author Olivier Monaco * @since 2015-02-03 * @issue https://github.com/phalcon/cphalcon/issues/3315 + * + * @dataProvider getUrlToSetWithoutDiTwoParam */ - public function shouldGetCorrectUrlWithGetParam(IntegrationTester $I) + public function shouldGetCorrectUrlWithGetParam(IntegrationTester $I, Example $example) { - $examples = $this->getUrlToSetWithoutDiTwoParam(); - foreach ($examples as $item) { - $params = $item[0]; - $expected = $item[1]; + $params = $example[0]; + $expected = $example[1]; - $url = $this->getService('url'); - $url->setBaseUri($params['base_url']); + $url = $this->getService('url'); - $actual = $url->get($params['get'], $params['second_get']); - $I->assertEquals($expected, $actual); - } + $url->setBaseUri( + $params['base_url'] + ); + + $actual = $url->get( + $params['get'], + $params['second_get'] + ); + + $I->assertEquals($expected, $actual); } private function getUrlToSetWithoutDiTwoParam(): array diff --git a/tests/integration/Mvc/Refactor-ViewEnginesCest.php b/tests/integration/Mvc/Refactor-ViewEnginesCest.php index 8660a28bab2..87f077875ba 100644 --- a/tests/integration/Mvc/Refactor-ViewEnginesCest.php +++ b/tests/integration/Mvc/Refactor-ViewEnginesCest.php @@ -17,6 +17,7 @@ namespace Phalcon\Test\Integration\Mvc; +use Codeception\Example; use IntegrationTester; use Phalcon\Mvc\View; use Phalcon\Mvc\View\Engine\Php; @@ -39,6 +40,7 @@ public function _before(IntegrationTester $I) { $this->newDi(); $this->setDiView(); + $this->level = ob_get_level(); } @@ -54,26 +56,44 @@ public function _after(IntegrationTester $I) * * @author Sergii Svyrydenko * @since 2017-01-29 + * + * @dataProvider getViewBuiltinFunction */ - public function shouldRenderVoltEngineBuiltInFunctions(IntegrationTester $I) + public function shouldRenderVoltEngineBuiltInFunctions(IntegrationTester $I, Example $example) { - $examples = $this->getViewBuiltinFunction(); - foreach ($examples as $item) { - $params = $item[0]; - $expected = $item[1]; - $view = $this->getService('view'); - $view->registerEngines($params['engines']); - foreach ($params['setVar'] as $var) { - $view->setVar($var[0], $var[1]); - } - $view->start(); - $view->render($params['render'][0], $params['render'][1]); - $view->finish(); + $params = $example[0]; + $expected = $example[1]; + + $view = $this->getService('view'); + + $view->registerEngines( + $params['engines'] + ); - $actual = $view->getContent(); - $I->assertEquals($expected, $actual); - $I->safeDeleteFile(dataFolder('fixtures/views/builtinfunction/index.volt.php')); + foreach ($params['setVar'] as $var) { + $view->setVar( + $var[0], + $var[1] + ); } + + $view->start(); + + $view->render( + $params['render'][0], + $params['render'][1] + ); + + $view->finish(); + + $I->assertEquals( + $expected, + $view->getContent() + ); + + $I->safeDeleteFile( + dataFolder('fixtures/views/builtinfunction/index.volt.php') + ); } private function getViewBuiltinFunction(): array diff --git a/tests/integration/Mvc/Router/RemoveExtraSlashesCest.php b/tests/integration/Mvc/Router/RemoveExtraSlashesCest.php index 468e205be37..9164b2f0527 100644 --- a/tests/integration/Mvc/Router/RemoveExtraSlashesCest.php +++ b/tests/integration/Mvc/Router/RemoveExtraSlashesCest.php @@ -12,6 +12,7 @@ namespace Phalcon\Test\Integration\Mvc\Router; +use Codeception\Example; use IntegrationTester; use Phalcon\Test\Fixtures\Traits\RouterTrait; @@ -29,39 +30,37 @@ class RemoveExtraSlashesCest * * @author Andy Gutierrez * @since 2012-12-16 + * + * @dataProvider getMatchingWithExtraSlashes */ - public function testRemovingExtraSlashes(IntegrationTester $I) + public function testRemovingExtraSlashes(IntegrationTester $I, Example $example) { $I->wantToTest('Mvc\Router - removeExtraSlashes()'); - $examples = $this->getMatchingWithExtraSlashes(); - - foreach ($examples as $item) { - $route = $item[0]; - $params = $item[1]; + $route = $example[0]; + $params = $example[1]; - $router = $this->getRouter(); + $router = $this->getRouter(); - $router->removeExtraSlashes(true); + $router->removeExtraSlashes(true); - $router->handle($route); + $router->handle($route); - $I->assertTrue( - $router->wasMatched() - ); + $I->assertTrue( + $router->wasMatched() + ); - $I->assertEquals( - $params['controller'], - $router->getControllerName() - ); + $I->assertEquals( + $params['controller'], + $router->getControllerName() + ); - $I->assertEquals( - $params['action'], - $router->getActionName() - ); - } + $I->assertEquals( + $params['action'], + $router->getActionName() + ); } private function getMatchingWithExtraSlashes(): array @@ -74,6 +73,7 @@ private function getMatchingWithExtraSlashes(): array 'action' => '', ], ], + [ '/session/start/', [ @@ -81,6 +81,7 @@ private function getMatchingWithExtraSlashes(): array 'action' => 'start', ], ], + [ '/users/edit/100/', [ diff --git a/tests/integration/Mvc/View/Engine/Volt/Compiler/AddFilterCest.php b/tests/integration/Mvc/View/Engine/Volt/Compiler/AddFilterCest.php index 23d0ab63456..84505a29bf4 100644 --- a/tests/integration/Mvc/View/Engine/Volt/Compiler/AddFilterCest.php +++ b/tests/integration/Mvc/View/Engine/Volt/Compiler/AddFilterCest.php @@ -12,6 +12,7 @@ namespace Phalcon\Test\Integration\Mvc\View\Engine\Volt\Compiler; +use Codeception\Example; use IntegrationTester; use Phalcon\Mvc\View\Engine\Volt\Compiler; @@ -27,22 +28,25 @@ class AddFilterCest * * @author Phalcon Team * @since 2018-11-13 + * + * @dataProvider getVoltAddFilter */ - public function mvcViewEngineVoltCompilerAddFilter(IntegrationTester $I) + public function mvcViewEngineVoltCompilerAddFilter(IntegrationTester $I, Example $example) { $I->wantToTest("Mvc\View\Engine\Volt\Compiler - addFilter()"); - $examples = $this->getVoltAddFilter(); - foreach ($examples as $item) { - $name = $item[0]; - $filter = $item[1]; - $voltName = $item[2]; - $expected = $item[3]; - - $volt = new Compiler(); - $volt->addFilter($name, $filter); - $actual = $volt->compileString($voltName); - $I->assertEquals($expected, $actual); - } + + $name = $example[0]; + $filter = $example[1]; + $voltName = $example[2]; + $expected = $example[3]; + + $volt = new Compiler(); + + $volt->addFilter($name, $filter); + + $actual = $volt->compileString($voltName); + + $I->assertEquals($expected, $actual); } /** @@ -51,7 +55,12 @@ public function mvcViewEngineVoltCompilerAddFilter(IntegrationTester $I) private function getVoltAddFilter(): array { return [ - ['reverse', 'strrev', '{{ "hello"|reverse }}', ''], + [ + 'reverse', + 'strrev', + '{{ "hello"|reverse }}', + '', + ], ]; } @@ -62,28 +71,31 @@ private function getVoltAddFilter(): array * * @author Phalcon Team * @since 2018-11-13 + * + * @dataProvider getVoltAddFilterClosure */ - public function mvcViewEngineVoltCompilerAddFilterClosure(IntegrationTester $I) + public function mvcViewEngineVoltCompilerAddFilterClosure(IntegrationTester $I, Example $example) { $I->wantToTest("Mvc\View\Engine\Volt\Compiler - addFilter() - closure"); - $examples = $this->getVoltAddFilterClosure(); - foreach ($examples as $item) { - $name = $item[0]; - $filter = $item[1]; - $voltName = $item[2]; - $expected = $item[3]; - - $volt = new Compiler(); - $volt->addFilter( - $name, - function ($arguments) use ($filter) { - return $filter . '(",", ' . $arguments . ')'; - } - ); - - $actual = $volt->compileString($voltName); - $I->assertEquals($expected, $actual); - } + + $name = $example[0]; + $filter = $example[1]; + $voltName = $example[2]; + $expected = $example[3]; + + $volt = new Compiler(); + + $volt->addFilter( + $name, + function ($arguments) use ($filter) { + return $filter . '(",", ' . $arguments . ')'; + } + ); + + $I->assertEquals( + $expected, + $volt->compileString($voltName) + ); } /** @@ -92,7 +104,12 @@ function ($arguments) use ($filter) { private function getVoltAddFilterClosure(): array { return [ - ['separate', 'explode', '{{ "1,2,3,4"|separate }}', ''], + [ + 'separate', + 'explode', + '{{ "1,2,3,4"|separate }}', + '', + ], ]; } } diff --git a/tests/integration/Mvc/View/Engine/Volt/Compiler/AddFunctionCest.php b/tests/integration/Mvc/View/Engine/Volt/Compiler/AddFunctionCest.php index 50207b0421e..54907c70580 100644 --- a/tests/integration/Mvc/View/Engine/Volt/Compiler/AddFunctionCest.php +++ b/tests/integration/Mvc/View/Engine/Volt/Compiler/AddFunctionCest.php @@ -12,6 +12,7 @@ namespace Phalcon\Test\Integration\Mvc\View\Engine\Volt\Compiler; +use Codeception\Example; use IntegrationTester; use Phalcon\Mvc\View\Engine\Volt\Compiler; @@ -27,23 +28,26 @@ class AddFunctionCest * * @author Phalcon Team * @since 2017-01-17 + * + * @dataProvider getVoltAddFunction */ - public function mvcViewEngineVoltCompilerAddFunction(IntegrationTester $I) + public function mvcViewEngineVoltCompilerAddFunction(IntegrationTester $I, Example $example) { $I->wantToTest("Mvc\View\Engine\Volt\Compiler - addFunction()"); - $examples = $this->getVoltAddFunction(); - foreach ($examples as $item) { - $name = $item[0]; - $funcName = $item[1]; - $voltName = $item[2]; - $expected = $item[3]; - - $volt = new Compiler(); - $volt->addFunction($name, $funcName); - - $actual = $volt->compileString($voltName); - $I->assertEquals($expected, $actual); - }; + + $name = $example[0]; + $funcName = $example[1]; + $voltName = $example[2]; + $expected = $example[3]; + + $volt = new Compiler(); + + $volt->addFunction($name, $funcName); + + $I->assertEquals( + $expected, + $volt->compileString($voltName) + ); } /** @@ -52,8 +56,19 @@ public function mvcViewEngineVoltCompilerAddFunction(IntegrationTester $I) private function getVoltAddFunction(): array { return [ - ['random', 'mt_rand', '{{ random() }}', ''], - ['strtotime', 'strtotime', '{{ strtotime("now") }}', ""], + [ + 'random', + 'mt_rand', + '{{ random() }}', + '', + ], + + [ + 'strtotime', + 'strtotime', + '{{ strtotime("now") }}', + "", + ], ]; } @@ -64,28 +79,31 @@ private function getVoltAddFunction(): array * * @author Phalcon Team * @since 2017-01-17 + * + * @dataProvider getVoltAddFunctionClosure */ - public function mvcViewEngineVoltCompilerAddFunctionClosure(IntegrationTester $I) + public function mvcViewEngineVoltCompilerAddFunctionClosure(IntegrationTester $I, Example $example) { $I->wantToTest("Mvc\View\Engine\Volt\Compiler - addFunction() - closure"); - $examples = $this->getVoltAddFunctionClosure(); - foreach ($examples as $item) { - $name = $item[0]; - $funcName = $item[1]; - $voltName = $item[2]; - $expected = $item[3]; - - $volt = new Compiler(); - $volt->addFunction( - $name, - function ($arguments) use ($funcName) { - return $funcName . '(' . $arguments . ')'; - } - ); - - $actual = $volt->compileString($voltName); - $I->assertEquals($expected, $actual); - }; + + $name = $example[0]; + $funcName = $example[1]; + $voltName = $example[2]; + $expected = $example[3]; + + $volt = new Compiler(); + + $volt->addFunction( + $name, + function ($arguments) use ($funcName) { + return $funcName . '(' . $arguments . ')'; + } + ); + + $I->assertEquals( + $expected, + $volt->compileString($voltName) + ); } /** @@ -94,7 +112,12 @@ function ($arguments) use ($funcName) { private function getVoltAddFunctionClosure(): array { return [ - ['shuffle', 'str_shuffle', '{{ shuffle("hello") }}', ''], + [ + 'shuffle', + 'str_shuffle', + '{{ shuffle("hello") }}', + '', + ], ]; } } diff --git a/tests/integration/Mvc/View/Engine/Volt/Compiler/CompileStringCest.php b/tests/integration/Mvc/View/Engine/Volt/Compiler/CompileStringCest.php index c10028eb29a..8e246f3b580 100644 --- a/tests/integration/Mvc/View/Engine/Volt/Compiler/CompileStringCest.php +++ b/tests/integration/Mvc/View/Engine/Volt/Compiler/CompileStringCest.php @@ -12,6 +12,7 @@ namespace Phalcon\Test\Integration\Mvc\View\Engine\Volt\Compiler; +use Codeception\Example; use IntegrationTester; use Phalcon\Mvc\View\Engine\Volt\Compiler; use Phalcon\Mvc\View\Exception; @@ -28,19 +29,22 @@ class CompileStringCest * * @author Phalcon Team * @since 2017-01-17 + * + * @dataProvider getVoltCompileString */ - public function mvcViewEngineVoltCompilerCompileString(IntegrationTester $I) + public function mvcViewEngineVoltCompilerCompileString(IntegrationTester $I, Example $example) { $I->wantToTest("Mvc\View\Engine\Volt\Compiler - compileString()"); - $examples = $this->getVoltCompileString(); - foreach ($examples as $item) { - $param = $item[0]; - $expected = $item[1]; - $volt = new Compiler(); - $actual = $volt->compileString($param); - $I->assertEquals($expected, $actual); - }; + $param = $example[0]; + $expected = $example[1]; + + $volt = new Compiler(); + + $I->assertEquals( + $expected, + $volt->compileString($param) + ); } /** @@ -254,22 +258,24 @@ private function getVoltCompileString(): array * * @author Phalcon Team * @since 2017-01-17 + * + * @dataProvider getVoltCompileStringErrors */ - public function mvcViewEngineVoltCompilerCompileStringSyntaxError(IntegrationTester $I) + public function mvcViewEngineVoltCompilerCompileStringSyntaxError(IntegrationTester $I, Example $example) { $I->wantToTest("Mvc\View\Engine\Volt\Compiler - compileString() - syntax error"); - $examples = $this->getVoltCompileStringErrors(); - foreach ($examples as $item) { - $code = $item[0]; - $message = $item[1]; - $volt = new Compiler(); - $I->expectThrowable( - new Exception($message), - function () use ($volt, $code) { - $volt->compileString($code); - } - ); - } + + $code = $example[0]; + $message = $example[1]; + + $volt = new Compiler(); + + $I->expectThrowable( + new Exception($message), + function () use ($volt, $code) { + $volt->compileString($code); + } + ); } /** diff --git a/tests/integration/Mvc/View/Engine/Volt/Compiler/ParseCest.php b/tests/integration/Mvc/View/Engine/Volt/Compiler/ParseCest.php index 5a7c58910ff..87f56330456 100644 --- a/tests/integration/Mvc/View/Engine/Volt/Compiler/ParseCest.php +++ b/tests/integration/Mvc/View/Engine/Volt/Compiler/ParseCest.php @@ -12,6 +12,7 @@ namespace Phalcon\Test\Integration\Mvc\View\Engine\Volt\Compiler; +use Codeception\Example; use IntegrationTester; use Phalcon\Mvc\View\Engine\Volt\Compiler; use Phalcon\Mvc\View\Exception; @@ -28,20 +29,24 @@ class ParseCest * * @author Phalcon Team * @since 2017-01-15 + * + * @dataProvider getVoltParse */ - public function mvcViewEngineVoltCompilerParse(IntegrationTester $I) + public function mvcViewEngineVoltCompilerParse(IntegrationTester $I, Example $example) { $I->wantToTest("Mvc\View\Engine\Volt\Compiler - parse()"); - $examples = $this->getVoltParse(); - foreach ($examples as $item) { - $param = $item[0]; - $count = $item[1]; - $volt = new Compiler(); - $actual = $volt->parse($param); - $I->assertTrue(is_array($actual)); - $I->assertCount($count, $actual); - } + $param = $example[0]; + $count = $example[1]; + + $volt = new Compiler(); + $actual = $volt->parse($param); + + $I->assertTrue( + is_array($actual) + ); + + $I->assertCount($count, $actual); } private function getVoltParse(): array @@ -192,22 +197,24 @@ private function getVoltParse(): array * * @author Phalcon Team * @since 2017-01-15 + * + * @dataProvider getVoltSyntaxErrors */ - public function mvcViewEngineVoltCompilerParseSyntaxError(IntegrationTester $I) + public function mvcViewEngineVoltCompilerParseSyntaxError(IntegrationTester $I, Example $example) { $I->wantToTest("Mvc\View\Engine\Volt\Compiler - parse() - syntax error"); - $examples = $this->getVoltSyntaxErrors(); - foreach ($examples as $item) { - $code = $item[0]; - $message = $item[1]; - $volt = new Compiler(); - $I->expectThrowable( - new Exception($message), - function () use ($volt, $code) { - $volt->parse($code); - } - ); - } + + $code = $example[0]; + $message = $example[1]; + + $volt = new Compiler(); + + $I->expectThrowable( + new Exception($message), + function () use ($volt, $code) { + $volt->parse($code); + } + ); } /** @@ -278,22 +285,24 @@ private function getVoltSyntaxErrors(): array * * @author Phalcon Team * @since 2017-01-15 + * + * @dataProvider getVoltExtendsError */ - public function mvcViewEngineVoltCompilerParseExtendsWithError(IntegrationTester $I) + public function mvcViewEngineVoltCompilerParseExtendsWithError(IntegrationTester $I, Example $example) { $I->wantToTest("Mvc\View\Engine\Volt\Compiler - parse() - extends with error"); - $examples = $this->getVoltExtendsError(); - foreach ($examples as $item) { - $code = $item[0]; - $message = $item[1]; - $volt = new Compiler(); - $I->expectThrowable( - new Exception($message), - function () use ($volt, $code) { - $volt->parse($code); - } - ); - } + + $code = $example[0]; + $message = $example[1]; + + $volt = new Compiler(); + + $I->expectThrowable( + new Exception($message), + function () use ($volt, $code) { + $volt->parse($code); + } + ); } /** diff --git a/tests/integration/Mvc/View/Engine/Volt/Compiler/SetOptionCest.php b/tests/integration/Mvc/View/Engine/Volt/Compiler/SetOptionCest.php index 912e454afa3..f9e74003abc 100644 --- a/tests/integration/Mvc/View/Engine/Volt/Compiler/SetOptionCest.php +++ b/tests/integration/Mvc/View/Engine/Volt/Compiler/SetOptionCest.php @@ -12,6 +12,7 @@ namespace Phalcon\Test\Integration\Mvc\View\Engine\Volt\Compiler; +use Codeception\Example; use IntegrationTester; use Phalcon\Mvc\View\Engine\Volt\Compiler; @@ -27,20 +28,24 @@ class SetOptionCest * * @author Phalcon Team * @since 2017-01-17 + * + * @dataProvider getVoltSetOptionAutoescape */ - public function mvcViewEngineVoltCompilerSetOptionAutoescape(IntegrationTester $I) + public function mvcViewEngineVoltCompilerSetOptionAutoescape(IntegrationTester $I, Example $example) { $I->wantToTest("Mvc\View\Engine\Volt\Compiler - setOption() - autoescape"); - $examples = $this->getVoltSetOptionAutoescape(); - foreach ($examples as $item) { - $param = $item[0]; - $expected = $item[1]; - $volt = new Compiler(); - $volt->setOption('autoescape', true); - - $actual = $volt->compileString($param); - $I->assertEquals($expected, $actual); - }; + + $param = $example[0]; + $expected = $example[1]; + + $volt = new Compiler(); + + $volt->setOption('autoescape', true); + + $I->assertEquals( + $expected, + $volt->compileString($param) + ); } /** diff --git a/tests/integration/Paginator/Adapter/NativeArray/ConstructCest.php b/tests/integration/Paginator/Adapter/NativeArray/ConstructCest.php index ad487f6ad9f..d835d5e0da9 100644 --- a/tests/integration/Paginator/Adapter/NativeArray/ConstructCest.php +++ b/tests/integration/Paginator/Adapter/NativeArray/ConstructCest.php @@ -32,6 +32,7 @@ class ConstructCest public function paginatorAdapterNativearrayConstruct(IntegrationTester $I) { $I->wantToTest('Paginator\Adapter\NativeArray - __construct()'); + $I->expectThrowable( new BadMethodCallException('Wrong number of parameters'), function () { diff --git a/tests/integration/Paginator/Adapter/NativeArray/GetLimitCest.php b/tests/integration/Paginator/Adapter/NativeArray/GetLimitCest.php index c9c05980e26..28df7ce5ab9 100644 --- a/tests/integration/Paginator/Adapter/NativeArray/GetLimitCest.php +++ b/tests/integration/Paginator/Adapter/NativeArray/GetLimitCest.php @@ -31,6 +31,7 @@ class GetLimitCest public function paginatorAdapterNativearrayGetLimit(IntegrationTester $I) { $I->wantToTest('Paginator\Adapter\NativeArray - getLimit()'); + $paginator = new NativeArray( [ 'data' => array_fill(0, 30, 'banana'), @@ -39,8 +40,9 @@ public function paginatorAdapterNativearrayGetLimit(IntegrationTester $I) ] ); - $expected = 25; - $actual = $paginator->getLimit(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 25, + $paginator->getLimit() + ); } } diff --git a/tests/integration/Paginator/Adapter/NativeArray/PaginateCest.php b/tests/integration/Paginator/Adapter/NativeArray/PaginateCest.php index 92f79d0adfa..7a8354e3881 100644 --- a/tests/integration/Paginator/Adapter/NativeArray/PaginateCest.php +++ b/tests/integration/Paginator/Adapter/NativeArray/PaginateCest.php @@ -32,6 +32,7 @@ class PaginateCest public function paginatorAdapterNativearrayPaginate(IntegrationTester $I) { $I->wantToTest('Paginator\Adapter\NativeArray - paginate()'); + $paginator = new NativeArray( [ 'data' => array_fill(0, 30, 'banana'), @@ -42,14 +43,39 @@ public function paginatorAdapterNativearrayPaginate(IntegrationTester $I) $page = $paginator->paginate(); - $expected = Repository::class; - $I->assertInstanceOf($expected, $page); + $I->assertInstanceOf( + Repository::class, + $page + ); + + $I->assertCount( + 25, + $page->getItems() + ); - $I->assertCount(25, $page->getItems()); - $I->assertEquals($page->getPrevious(), 1); - $I->assertEquals($page->getNext(), 2); - $I->assertEquals($page->getLast(), 2); - $I->assertEquals($page->getLimit(), 25); - $I->assertEquals($page->getCurrent(), 1); + $I->assertEquals( + 1, + $page->getPrevious() + ); + + $I->assertEquals( + 2, + $page->getNext() + ); + + $I->assertEquals( + 2, + $page->getLast() + ); + + $I->assertEquals( + 25, + $page->getLimit() + ); + + $I->assertEquals( + 1, + $page->getCurrent() + ); } } diff --git a/tests/integration/Paginator/Adapter/NativeArray/SetCurrentPageCest.php b/tests/integration/Paginator/Adapter/NativeArray/SetCurrentPageCest.php index 2df1ca8f95c..34391fbbf14 100644 --- a/tests/integration/Paginator/Adapter/NativeArray/SetCurrentPageCest.php +++ b/tests/integration/Paginator/Adapter/NativeArray/SetCurrentPageCest.php @@ -32,6 +32,7 @@ class SetCurrentPageCest public function paginatorAdapterNativearraySetCurrentPage(IntegrationTester $I) { $I->wantToTest('Paginator\Adapter\NativeArray - setCurrentPage()'); + $paginator = new NativeArray( [ 'data' => array_fill(0, 30, 'banana'), @@ -41,10 +42,13 @@ public function paginatorAdapterNativearraySetCurrentPage(IntegrationTester $I) ); $paginator->setCurrentPage(2); + $page = $paginator->paginate(); - $expected = Repository::class; - $I->assertInstanceOf($expected, $page); + $I->assertInstanceOf( + Repository::class, + $page + ); $I->assertCount(10, $page->items); $I->assertEquals(1, $page->previous); diff --git a/tests/integration/Paginator/Adapter/NativeArray/SetLimitCest.php b/tests/integration/Paginator/Adapter/NativeArray/SetLimitCest.php index 071e9c7104c..8f09f35b942 100644 --- a/tests/integration/Paginator/Adapter/NativeArray/SetLimitCest.php +++ b/tests/integration/Paginator/Adapter/NativeArray/SetLimitCest.php @@ -31,6 +31,7 @@ class SetLimitCest public function paginatorAdapterNativearraySetLimit(IntegrationTester $I) { $I->wantToTest('Paginator\Adapter\NativeArray - setLimit()'); + $paginator = new NativeArray( [ 'data' => array_fill(0, 30, 'banana'), @@ -39,14 +40,20 @@ public function paginatorAdapterNativearraySetLimit(IntegrationTester $I) ] ); - $expected = 25; - $actual = $paginator->getLimit(); - $I->assertEquals($expected, $actual); + + + $I->assertEquals( + 25, + $paginator->getLimit() + ); + + $paginator->setLimit(10); - $expected = 10; - $actual = $paginator->getLimit(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 10, + $paginator->getLimit() + ); } } diff --git a/tests/integration/Paginator/Adapter/QueryBuilderCest.php b/tests/integration/Paginator/Adapter/QueryBuilderCest.php index 5d663f2c708..7b84b348b29 100644 --- a/tests/integration/Paginator/Adapter/QueryBuilderCest.php +++ b/tests/integration/Paginator/Adapter/QueryBuilderCest.php @@ -38,7 +38,9 @@ public function _before(IntegrationTester $I) public function testIssue12111WithGroup(IntegrationTester $I) { $this->setDiMysql(); + $manager = $this->getService('modelsManager'); + $builder = $manager ->createBuilder() ->columns("name, COUNT(*) as stock_count") @@ -72,7 +74,9 @@ public function testIssue12111WithoutGroupException(IntegrationTester $I) new Exception('When having is set there should be columns option provided for which calculate row count'), function () { $this->setDiMysql(); + $manager = $this->getService('modelsManager'); + $builder = $manager ->createBuilder() ->columns("COUNT(*) as stock_count") @@ -100,13 +104,15 @@ function () { public function testIssue12111WithoutGroup(IntegrationTester $I) { $this->setDiMysql(); + $db = $this->getService('db'); + /* - * There is no clean way to rewrite query builder's query in the - * strict mode: if we remove all nonaggregated columns, we will get - * "Unknown column 'Stock.stock' in 'having clause'", otherwise - * "In aggregated query without GROUP BY, expression #1 of SELECT - * list contains nonaggregated column 'phalcon_test.Stock.stock'" + * There is no clean way to rewrite query builder's query in the strict + * mode: if we remove all nonaggregated columns, we will get "Unknown + * column 'Stock.stock' in 'having clause'", otherwise "In aggregated + * query without GROUP BY, expression #1 of SELECT list contains + * non-aggregated column 'phalcon_test.Stock.stock'" */ $db->query( "SET SESSION sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE," . @@ -114,6 +120,7 @@ public function testIssue12111WithoutGroup(IntegrationTester $I) ); $manager = $this->getService('modelsManager'); + $builder = $manager ->createBuilder() ->columns("*, COUNT(*) as stock_count") @@ -144,6 +151,7 @@ public function testIssue12111WithoutGroup(IntegrationTester $I) public function testIssue12957(IntegrationTester $I) { $this->setDiMysql(); + $modelsManager = $this->getService('modelsManager'); $this->container->set( @@ -180,6 +188,7 @@ public function testIssue12957(IntegrationTester $I) public function testIssue13552(IntegrationTester $I) { $this->setDiMysql(); + $modelsManager = $this->getService('modelsManager'); $builder = $modelsManager->createBuilder() diff --git a/tests/integration/Paginator/Adapter/RepositoryCest.php b/tests/integration/Paginator/Adapter/RepositoryCest.php index 145bb6e655f..29049220a3a 100644 --- a/tests/integration/Paginator/Adapter/RepositoryCest.php +++ b/tests/integration/Paginator/Adapter/RepositoryCest.php @@ -26,45 +26,72 @@ class RepositoryCest public function testRepositoryPaginator(IntegrationTester $I) { $paginatorRepository = new \Phalcon\Paginator\Repository(); - $paginatorRepository->setAliases([ - 'myFirstPage' => $paginatorRepository::PROPERTY_FIRST_PAGE, - 'myLastPage' => $paginatorRepository::PROPERTY_LAST_PAGE, - 'myCurrentPage' => $paginatorRepository::PROPERTY_CURRENT_PAGE, - 'myLimit' => $paginatorRepository::PROPERTY_LIMIT, - ]); - - $paginator = new \Phalcon\Paginator\Adapter\NativeArray([ - 'data' => array_fill(0, 30, 'banana'), - 'limit' => 25, - 'page' => 1, - 'repository' => $paginatorRepository, - ]); + + $paginatorRepository->setAliases( + [ + 'myFirstPage' => $paginatorRepository::PROPERTY_FIRST_PAGE, + 'myLastPage' => $paginatorRepository::PROPERTY_LAST_PAGE, + 'myCurrentPage' => $paginatorRepository::PROPERTY_CURRENT_PAGE, + 'myLimit' => $paginatorRepository::PROPERTY_LIMIT, + ] + ); + + $paginator = new \Phalcon\Paginator\Adapter\NativeArray( + [ + 'data' => array_fill(0, 30, 'banana'), + 'limit' => 25, + 'page' => 1, + 'repository' => $paginatorRepository, + ] + ); $page = $paginator->paginate(); - $I->assertInstanceOf(\Phalcon\Paginator\Repository::class, $page); + + $I->assertInstanceOf( + \Phalcon\Paginator\Repository::class, + $page + ); + + + // Test getters - $I->assertEquals(count($page->getItems()), 25); - $I->assertEquals($page->getPrevious(), 1); - $I->assertEquals($page->getNext(), 2); - $I->assertEquals($page->getLast(), 2); - $I->assertEquals($page->getLimit(), 25); - $I->assertEquals($page->getCurrent(), 1); + $I->assertCount(25, $page->getItems()); + $I->assertEquals(1, $page->getPrevious()); + $I->assertEquals(2, $page->getNext()); + $I->assertEquals(2, $page->getLast()); + $I->assertEquals(25, $page->getLimit()); + $I->assertEquals(1, $page->getCurrent()); + + + // Test aliases - $I->assertEquals($page->myLastPage, 2); - $I->assertEquals($page->myLimit, 25); - $I->assertEquals($page->myCurrentPage, 1); + $I->assertEquals(2, $page->myLastPage); + $I->assertEquals(25, $page->myLimit); + $I->assertEquals(1, $page->myCurrentPage); + $paginator->setCurrentPage(2); + $page = $paginator->paginate(); - $I->assertInstanceOf(\Phalcon\Paginator\Repository::class, $page); + + $I->assertInstanceOf( + \Phalcon\Paginator\Repository::class, + $page + ); + + + // Test magic getters - $I->assertEquals(count($page->items), 5); - $I->assertEquals($page->previous, 1); - $I->assertEquals($page->next, 2); - $I->assertEquals($page->last, 2); - $I->assertEquals($page->current, 2); + $I->assertCount(5, $page->items); + $I->assertEquals(1, $page->previous); + $I->assertEquals(2, $page->next); + $I->assertEquals(2, $page->last); + $I->assertEquals(2, $page->current); + + + // Test aliases - $I->assertEquals($page->myLastPage, 2); - $I->assertEquals($page->myLimit, 25); - $I->assertEquals($page->myCurrentPage, 2); + $I->assertEquals(2, $page->myLastPage); + $I->assertEquals(25, $page->myLimit); + $I->assertEquals(2, $page->myCurrentPage); } } diff --git a/tests/integration/Paginator/Factory/LoadCest.php b/tests/integration/Paginator/Factory/LoadCest.php index c7a6e4350af..ce8023962f5 100644 --- a/tests/integration/Paginator/Factory/LoadCest.php +++ b/tests/integration/Paginator/Factory/LoadCest.php @@ -37,8 +37,11 @@ class LoadCest public function paginatorFactoryLoadConfig(IntegrationTester $I) { $I->wantToTest("Paginator\Factory - load() - Config"); + $I->skipTest("TODO: need to check this"); + $this->setNewFactoryDefault(); + $options = $this->config->paginator; $options->builder = $this ->container @@ -48,8 +51,10 @@ public function paginatorFactoryLoadConfig(IntegrationTester $I) ->from("Robots") ->orderBy("name") ; + /** @var QueryBuilder $paginator */ $paginator = Factory::load($options); + $I->assertInstanceOf(QueryBuilder::class, $paginator); $I->assertEquals($options->limit, $paginator->getLimit()); $I->assertEquals($options->page, $paginator->getCurrentPage()); @@ -66,8 +71,11 @@ public function paginatorFactoryLoadConfig(IntegrationTester $I) public function paginatorFactoryLoadArray(IntegrationTester $I) { $I->wantToTest("Paginator\Factory - load() - array"); + $I->skipTest("TODO: need to check this"); + $this->setNewFactoryDefault(); + $options = $this->arrayConfig["paginator"]; $options["builder"] = $this ->container @@ -77,10 +85,23 @@ public function paginatorFactoryLoadArray(IntegrationTester $I) ->from("Robots") ->orderBy("name") ; + /** @var QueryBuilder $paginator */ $paginator = Factory::load($options); - $I->assertInstanceOf(QueryBuilder::class, $paginator); - $I->assertEquals($options["limit"], $paginator->getLimit()); - $I->assertEquals($options["page"], $paginator->getCurrentPage()); + + $I->assertInstanceOf( + QueryBuilder::class, + $paginator + ); + + $I->assertEquals( + $options["limit"], + $paginator->getLimit() + ); + + $I->assertEquals( + $options["page"], + $paginator->getCurrentPage() + ); } } diff --git a/tests/integration/Refactor-PaginatorCest.php b/tests/integration/Refactor-PaginatorCest.php index 5f3c6d6ddde..396b3c92240 100644 --- a/tests/integration/Refactor-PaginatorCest.php +++ b/tests/integration/Refactor-PaginatorCest.php @@ -32,7 +32,9 @@ public function _before(IntegrationTester $I) public function testModelPaginator(IntegrationTester $I) { $I->skipTest('TODO: Check me'); + $personnes = Personnes::find(); + $paginator = new Model( [ 'data' => $personnes, @@ -43,58 +45,73 @@ public function testModelPaginator(IntegrationTester $I) //First Page $page = $paginator->paginate(); - $I->assertInstanceOf('stdClass', $page); + + $I->assertInstanceOf( + \stdClass::class, + $page + ); $I->assertCount(10, $page->items); - $I->assertEquals($page->before, 1); - $I->assertEquals($page->next, 2); - $I->assertEquals($page->last, 218); - $I->assertEquals($page->limit, 10); + $I->assertEquals(1, $page->before); + $I->assertEquals(2, $page->next); + $I->assertEquals(218, $page->last); + $I->assertEquals(10, $page->limit); - $I->assertEquals($page->current, 1); - $I->assertEquals($page->total_pages, 218); + $I->assertEquals(1, $page->current); + $I->assertEquals(218, $page->total_pages); //Middle Page $paginator->setCurrentPage(50); $page = $paginator->paginate(); - $I->assertInstanceOf('stdClass', $page); + + $I->assertInstanceOf( + \stdClass::class, + $page + ); $I->assertCount(10, $page->items); - $I->assertEquals($page->before, 49); - $I->assertEquals($page->next, 51); - $I->assertEquals($page->last, 218); + $I->assertEquals(49, $page->before); + $I->assertEquals(51, $page->next); + $I->assertEquals(218, $page->last); - $I->assertEquals($page->current, 50); - $I->assertEquals($page->total_pages, 218); + $I->assertEquals(50, $page->current); + $I->assertEquals(218, $page->total_pages); //Last Page $paginator->setCurrentPage(218); $page = $paginator->paginate(); - $I->assertInstanceOf('stdClass', $page); + + $I->assertInstanceOf( + \stdClass::class, + $page + ); $I->assertCount(10, $page->items); - $I->assertEquals($page->before, 217); - $I->assertEquals((int) $page->next, 218); - $I->assertEquals($page->last, 218); + $I->assertEquals(217, $page->before); + $I->assertEquals(218, (int) $page->next); + $I->assertEquals(218, $page->last); - $I->assertEquals($page->current, 218); - $I->assertEquals($page->total_pages, 218); + $I->assertEquals(218, $page->current); + $I->assertEquals(218, $page->total_pages); } public function testModelPaginatorBind(IntegrationTester $I) { $I->skipTest('TODO: Check me'); - $personnes = Personnes::find([ - "conditions" => "cedula >=:d1: AND cedula>=:d2: ", - "bind" => ["d1" => '1', "d2" => "5"], - "order" => "cedula, nombres", - "limit" => "33", - ]); + + $personnes = Personnes::find( + [ + "conditions" => "cedula >=:d1: AND cedula>=:d2: ", + "bind" => ["d1" => '1', "d2" => "5"], + "order" => "cedula, nombres", + "limit" => "33", + ] + ); $paginator = new Model( [ @@ -106,23 +123,29 @@ public function testModelPaginatorBind(IntegrationTester $I) //First Page $page = $paginator->paginate(); - $I->assertInstanceOf('stdClass', $page); + + $I->assertInstanceOf( + \stdClass::class, + $page + ); $I->assertCount(10, $page->items); - $I->assertEquals($page->before, 1); - $I->assertEquals($page->next, 2); - $I->assertEquals($page->last, 4); - $I->assertEquals($page->limit, 10); + $I->assertEquals(1, $page->before); + $I->assertEquals(2, $page->next); + $I->assertEquals(4, $page->last); + $I->assertEquals(10, $page->limit); - $I->assertEquals($page->current, 1); - $I->assertEquals($page->total_pages, 4); + $I->assertEquals(1, $page->current); + $I->assertEquals(4, $page->total_pages); } public function testQueryBuilderPaginator(IntegrationTester $I) { $I->skipTest('TODO - Check me'); + $manager = $this->getService('modelsManager'); + $builder = $manager->createBuilder() ->columns('cedula, nombres') ->from('Personnes') @@ -139,18 +162,21 @@ public function testQueryBuilderPaginator(IntegrationTester $I) $page = $paginator->paginate(); - $I->assertInstanceOf('stdClass', $page); + $I->assertInstanceOf( + \stdClass::class, + $page + ); $I->assertCount(10, $page->items); - $I->assertEquals($page->before, 1); - $I->assertEquals($page->next, 2); - $I->assertEquals($page->last, 218); - $I->assertEquals($page->limit, 10); + $I->assertEquals(1, $page->before); + $I->assertEquals(2, $page->next); + $I->assertEquals(218, $page->last); + $I->assertEquals(10, $page->limit); - $I->assertEquals($page->current, 1); - $I->assertEquals($page->total_items, 2180); - $I->assertEquals($page->total_pages, 218); + $I->assertEquals(1, $page->current); + $I->assertEquals(2180, $page->total_items); + $I->assertEquals(218, $page->total_pages); $I->assertInternalType('int', $page->total_items); $I->assertInternalType('int', $page->total_pages); @@ -160,16 +186,19 @@ public function testQueryBuilderPaginator(IntegrationTester $I) $page = $paginator->paginate(); - $I->assertInstanceOf('stdClass', $page); + $I->assertInstanceOf( + \stdClass::class, + $page + ); $I->assertCount(10, $page->items); - $I->assertEquals($page->before, 99); - $I->assertEquals($page->next, 101); - $I->assertEquals($page->last, 218); + $I->assertEquals(99, $page->before); + $I->assertEquals(101, $page->next); + $I->assertEquals(218, $page->last); - $I->assertEquals($page->current, 100); - $I->assertEquals($page->total_pages, 218); + $I->assertEquals(100, $page->current); + $I->assertEquals(218, $page->total_pages); $I->assertInternalType('int', $page->total_items); $I->assertInternalType('int', $page->total_pages); @@ -183,12 +212,12 @@ public function testQueryBuilderPaginator(IntegrationTester $I) $I->assertCount(10, $page->items); - $I->assertEquals($page->before, 217); - $I->assertEquals($page->next, 218); - $I->assertEquals($page->last, 218); + $I->assertEquals(217, $page->before); + $I->assertEquals(218, $page->next); + $I->assertEquals(218, $page->last); - $I->assertEquals($page->current, 218); - $I->assertEquals($page->total_pages, 218); + $I->assertEquals(218, $page->current); + $I->assertEquals(218, $page->total_pages); $I->assertInternalType('int', $page->total_items); $I->assertInternalType('int', $page->total_pages); @@ -197,16 +226,16 @@ public function testQueryBuilderPaginator(IntegrationTester $I) // -- current page -- $currentPage = $paginator->getCurrentPage(); - $I->assertEquals($currentPage, 218); + $I->assertEquals(218, $currentPage); // -- limit -- $rowsLimit = $paginator->getLimit(); - $I->assertEquals($rowsLimit, 10); + $I->assertEquals(10, $rowsLimit); $setterResult = $paginator->setLimit(25); $rowsLimit = $paginator->getLimit(); - $I->assertEquals($rowsLimit, 25); - $I->assertEquals($setterResult, $paginator); + $I->assertEquals(25, $rowsLimit); + $I->assertEquals($paginator, $setterResult); // -- builder -- $queryBuilder = $paginator->getQueryBuilder(); @@ -220,13 +249,15 @@ public function testQueryBuilderPaginator(IntegrationTester $I) $setterResult = $paginator->setQueryBuilder($builder2); $queryBuilder = $paginator->getQueryBuilder(); $I->assertEquals($builder2, $queryBuilder); - $I->assertEquals($setterResult, $paginator); + $I->assertEquals($paginator, $setterResult); } public function testQueryBuilderPaginatorGroupBy(IntegrationTester $I) { $I->skipTest('TODO: Check me'); + $database = $this->getService('db'); + $database->query( "SET SESSION sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE," . "NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER," . @@ -235,6 +266,7 @@ public function testQueryBuilderPaginatorGroupBy(IntegrationTester $I) // test paginator with group by string value $manager = $this->getService('modelsManager'); + $builder = $manager->createBuilder() ->columns('cedula, nombres') ->from('Personnes') @@ -266,16 +298,17 @@ public function testQueryBuilderPaginatorGroupBy(IntegrationTester $I) // -- current page -- $currentPage = $paginator->getCurrentPage(); - $I->assertEquals($currentPage, 18); + + $I->assertEquals(18, $currentPage); // -- limit -- $rowsLimit = $paginator->getLimit(); - $I->assertEquals($rowsLimit, 10); + $I->assertEquals(10, $rowsLimit); $setterResult = $paginator->setLimit(25); $rowsLimit = $paginator->getLimit(); - $I->assertEquals($rowsLimit, 25); - $I->assertEquals($setterResult, $paginator); + $I->assertEquals(25, $rowsLimit); + $I->assertEquals($paginator, $setterResult); // -- builder -- $queryBuilder = $paginator->getQueryBuilder(); @@ -290,16 +323,18 @@ public function testQueryBuilderPaginatorGroupBy(IntegrationTester $I) $setterResult = $paginator->setQueryBuilder($builder2); $queryBuilder = $paginator->getQueryBuilder(); $I->assertEquals($builder2, $queryBuilder); - $I->assertEquals($setterResult, $paginator); + $I->assertEquals($paginator, $setterResult); } private function paginatorBuilderTest(IntegrationTester $I, $builder) { - $paginator = new QueryBuilder([ - "builder" => $builder, - "limit" => 10, - "page" => 1, - ]); + $paginator = new QueryBuilder( + [ + "builder" => $builder, + "limit" => 10, + "page" => 1, + ] + ); $page = $paginator->paginate(); @@ -307,14 +342,14 @@ private function paginatorBuilderTest(IntegrationTester $I, $builder) $I->assertCount(10, $page->items); - $I->assertEquals($page->before, 1); - $I->assertEquals($page->next, 2); - $I->assertEquals($page->last, 18); - $I->assertEquals($page->limit, 10); + $I->assertEquals(1, $page->before); + $I->assertEquals(2, $page->next); + $I->assertEquals(18, $page->last); + $I->assertEquals(10, $page->limit); - $I->assertEquals($page->current, 1); - $I->assertEquals($page->total_items, 178); - $I->assertEquals($page->total_pages, 18); + $I->assertEquals(1, $page->current); + $I->assertEquals(178, $page->total_items); + $I->assertEquals(18, $page->total_pages); $I->assertInternalType('int', $page->total_items); $I->assertInternalType('int', $page->total_pages); @@ -328,12 +363,12 @@ private function paginatorBuilderTest(IntegrationTester $I, $builder) $I->assertCount(10, $page->items); - $I->assertEquals($page->before, 9); - $I->assertEquals($page->next, 11); - $I->assertEquals($page->last, 18); + $I->assertEquals(9, $page->before); + $I->assertEquals(11, $page->next); + $I->assertEquals(18, $page->last); - $I->assertEquals($page->current, 10); - $I->assertEquals($page->total_pages, 18); + $I->assertEquals(10, $page->current); + $I->assertEquals(18, $page->total_pages); $I->assertInternalType('int', $page->total_items); $I->assertInternalType('int', $page->total_pages); @@ -343,16 +378,19 @@ private function paginatorBuilderTest(IntegrationTester $I, $builder) $page = $paginator->paginate(); - $I->assertInstanceOf('stdClass', $page); + $I->assertInstanceOf( + \stdClass::class, + $page + ); $I->assertCount(9, $page->items); - $I->assertEquals($page->before, 17); - $I->assertEquals($page->next, 18); - $I->assertEquals($page->last, 18); + $I->assertEquals(17, $page->before); + $I->assertEquals(18, $page->next); + $I->assertEquals(18, $page->last); - $I->assertEquals($page->current, 18); - $I->assertEquals($page->total_pages, 18); + $I->assertEquals(18, $page->current); + $I->assertEquals(18, $page->total_pages); $I->assertInternalType('int', $page->total_items); $I->assertInternalType('int', $page->total_pages); diff --git a/tests/integration/Refactor-ValidationCest.php b/tests/integration/Refactor-ValidationCest.php index 8062ba60d64..c18c0563622 100644 --- a/tests/integration/Refactor-ValidationCest.php +++ b/tests/integration/Refactor-ValidationCest.php @@ -54,6 +54,10 @@ public function appendValidationMessageToTheNonObject(IntegrationTester $I) ), ] ); - $I->assertEquals($expectedMessages, $validation->getMessages()); + + $I->assertEquals( + $expectedMessages, + $validation->getMessages() + ); } } diff --git a/tests/integration/Session/Adapter/Files/CloseCest.php b/tests/integration/Session/Adapter/Files/CloseCest.php index c0a3f6f5ffb..599bb23907c 100644 --- a/tests/integration/Session/Adapter/Files/CloseCest.php +++ b/tests/integration/Session/Adapter/Files/CloseCest.php @@ -43,8 +43,11 @@ public function _before(IntegrationTester $I) public function sessionAdapterFilesClose(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Files - close()'); + $adapter = $this->getSessionFiles(); - $actual = $adapter->close(); - $I->assertTrue($actual); + + $I->assertTrue( + $adapter->close() + ); } } diff --git a/tests/integration/Session/Adapter/Files/ConstructCest.php b/tests/integration/Session/Adapter/Files/ConstructCest.php index 6d6e27442c4..91e5c601a15 100644 --- a/tests/integration/Session/Adapter/Files/ConstructCest.php +++ b/tests/integration/Session/Adapter/Files/ConstructCest.php @@ -44,8 +44,12 @@ public function _before(IntegrationTester $I) public function sessionAdapterFilesConstruct(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Files - __construct()'); + $adapter = $this->getSessionFiles(); - $class = SessionHandlerInterface::class; - $I->assertInstanceOf($class, $adapter); + + $I->assertInstanceOf( + SessionHandlerInterface::class, + $adapter + ); } } diff --git a/tests/integration/Session/Adapter/Files/DestroyCest.php b/tests/integration/Session/Adapter/Files/DestroyCest.php index 6a142b82b83..ba974c40c97 100644 --- a/tests/integration/Session/Adapter/Files/DestroyCest.php +++ b/tests/integration/Session/Adapter/Files/DestroyCest.php @@ -46,15 +46,24 @@ public function _before(IntegrationTester $I) public function sessionAdapterFilesDestroy(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Files - destroy()'); + $adapter = $this->getSessionFiles(); /** * Create a file in the session folder */ - file_put_contents(cacheFolder('test1'), uniqid()); - $actual = $adapter->destroy('test1'); - $I->assertTrue($actual); + file_put_contents( + cacheFolder('test1'), + uniqid() + ); + + $I->assertTrue( + $adapter->destroy('test1') + ); - $I->dontSeeFileFound('test1', cacheFolder()); + $I->dontSeeFileFound( + 'test1', + cacheFolder() + ); } } diff --git a/tests/integration/Session/Adapter/Files/GcCest.php b/tests/integration/Session/Adapter/Files/GcCest.php index 12c60592f03..f55111ad73c 100644 --- a/tests/integration/Session/Adapter/Files/GcCest.php +++ b/tests/integration/Session/Adapter/Files/GcCest.php @@ -47,21 +47,40 @@ public function _before(IntegrationTester $I) public function sessionAdapterFilesGc(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Files - gc()'); + $adapter = $this->getSessionFiles(); + + /** * Add two session files */ - file_put_contents(cacheFolder('gc_1'), uniqid()); - file_put_contents(cacheFolder('gc_2'), uniqid()); + file_put_contents( + cacheFolder('gc_1'), + uniqid() + ); + + file_put_contents( + cacheFolder('gc_2'), + uniqid() + ); + + /** * Sleep to make sure that the time expired */ sleep(2); - $actual = $adapter->gc(1); - $I->assertTrue($actual); - $I->amInPath(cacheFolder()); + + $I->assertTrue( + $adapter->gc(1) + ); + + $I->amInPath( + cacheFolder() + ); + $I->dontSeeFileFound('gc_1'); + $I->dontSeeFileFound('gc_2'); } } diff --git a/tests/integration/Session/Adapter/Files/OpenCest.php b/tests/integration/Session/Adapter/Files/OpenCest.php index d7720fa3fb1..3964b630d00 100644 --- a/tests/integration/Session/Adapter/Files/OpenCest.php +++ b/tests/integration/Session/Adapter/Files/OpenCest.php @@ -43,8 +43,14 @@ public function _before(IntegrationTester $I) public function sessionAdapterFilesOpen(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Files - open()'); + $adapter = $this->getSessionFiles(); - $actual = $adapter->open(cacheFolder(), 'test1'); + + $actual = $adapter->open( + cacheFolder(), + 'test1' + ); + $I->assertTrue($actual); } } diff --git a/tests/integration/Session/Adapter/Files/ReadCest.php b/tests/integration/Session/Adapter/Files/ReadCest.php index 733ab294b3b..a280a3d6e48 100644 --- a/tests/integration/Session/Adapter/Files/ReadCest.php +++ b/tests/integration/Session/Adapter/Files/ReadCest.php @@ -45,14 +45,20 @@ public function _before(IntegrationTester $I) public function sessionAdapterFilesRead(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Files - write()'); + $adapter = $this->getSessionFiles(); $value = uniqid(); + $adapter->write('test1', $value); $expected = $value; $actual = $adapter->read('test1'); + $I->assertEquals($expected, $actual); - $I->safeDeleteFile(cacheFolder('test1')); + + $I->safeDeleteFile( + cacheFolder('test1') + ); } } diff --git a/tests/integration/Session/Adapter/Files/WriteCest.php b/tests/integration/Session/Adapter/Files/WriteCest.php index 6ef6ce873b7..7ad5c3cbbac 100644 --- a/tests/integration/Session/Adapter/Files/WriteCest.php +++ b/tests/integration/Session/Adapter/Files/WriteCest.php @@ -45,12 +45,23 @@ public function _before(IntegrationTester $I) public function sessionAdapterFilesWrite(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Files - write()'); + $adapter = $this->getSessionFiles(); - $value = uniqid(); + + $value = uniqid(); + $adapter->write('test1', $value); - $I->amInPath(cacheFolder()); + + $I->amInPath( + cacheFolder() + ); + $I->seeFileFound('test1'); + $I->seeInThisFile($value); - $I->safeDeleteFile(cacheFolder('test1')); + + $I->safeDeleteFile( + cacheFolder('test1') + ); } } diff --git a/tests/integration/Session/Adapter/Libmemcached/CloseCest.php b/tests/integration/Session/Adapter/Libmemcached/CloseCest.php index f719b93258c..0f80d351274 100644 --- a/tests/integration/Session/Adapter/Libmemcached/CloseCest.php +++ b/tests/integration/Session/Adapter/Libmemcached/CloseCest.php @@ -43,8 +43,11 @@ public function _before(IntegrationTester $I) public function sessionAdapterLibmemcachedClose(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Libmemcached - close()'); + $adapter = $this->getSessionLibmemcached(); - $actual = $adapter->close(); - $I->assertTrue($actual); + + $I->assertTrue( + $adapter->close() + ); } } diff --git a/tests/integration/Session/Adapter/Libmemcached/ConstructCest.php b/tests/integration/Session/Adapter/Libmemcached/ConstructCest.php index 28d765f0f23..e8159c09e57 100644 --- a/tests/integration/Session/Adapter/Libmemcached/ConstructCest.php +++ b/tests/integration/Session/Adapter/Libmemcached/ConstructCest.php @@ -44,8 +44,12 @@ public function _before(IntegrationTester $I) public function sessionAdapterLibmemcachedConstruct(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Libmemcached - __construct()'); + $adapter = $this->getSessionLibmemcached(); - $class = SessionHandlerInterface::class; - $I->assertInstanceOf($class, $adapter); + + $I->assertInstanceOf( + SessionHandlerInterface::class, + $adapter + ); } } diff --git a/tests/integration/Session/Adapter/Libmemcached/DestroyCest.php b/tests/integration/Session/Adapter/Libmemcached/DestroyCest.php index 19d6084a0d8..7a11cf8c4c3 100644 --- a/tests/integration/Session/Adapter/Libmemcached/DestroyCest.php +++ b/tests/integration/Session/Adapter/Libmemcached/DestroyCest.php @@ -44,13 +44,18 @@ public function _before(IntegrationTester $I) public function sessionAdapterLibmemcachedDestroy(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Libmemcached - destroy()'); + $adapter = $this->getSessionLibmemcached(); $value = uniqid(); $serialized = serialize($value); + $I->haveInLibmemcached('test1', $serialized); - $actual = $adapter->destroy('test1'); - $I->assertTrue($actual); + + $I->assertTrue( + $adapter->destroy('test1') + ); + $I->dontSeeInLibmemcached('test1'); } } diff --git a/tests/integration/Session/Adapter/Libmemcached/GcCest.php b/tests/integration/Session/Adapter/Libmemcached/GcCest.php index 80f7126292d..36e47b259bb 100644 --- a/tests/integration/Session/Adapter/Libmemcached/GcCest.php +++ b/tests/integration/Session/Adapter/Libmemcached/GcCest.php @@ -45,20 +45,37 @@ public function _before(IntegrationTester $I) public function sessionAdapterLibmemcachedGc(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Libmemcached - gc()'); + $adapter = $this->getSessionLibmemcached(); /** * Add two session keys */ - $I->haveInLibmemcached('gc_1', uniqid(), 1); - $I->haveInLibmemcached('gc_2', uniqid(), 1); + $I->haveInLibmemcached( + 'gc_1', + uniqid(), + 1 + ); + + $I->haveInLibmemcached( + 'gc_2', + uniqid(), + 1 + ); + + + /** * Sleep to make sure that the time expired */ sleep(2); - $actual = $adapter->gc(1); - $I->assertTrue($actual); + + $I->assertTrue( + $adapter->gc(1) + ); + $I->dontSeeInLibmemcached('gc_1'); + $I->dontSeeInLibmemcached('gc_2'); } } diff --git a/tests/integration/Session/Adapter/Libmemcached/OpenCest.php b/tests/integration/Session/Adapter/Libmemcached/OpenCest.php index ab7c9ea4576..e3666a93447 100644 --- a/tests/integration/Session/Adapter/Libmemcached/OpenCest.php +++ b/tests/integration/Session/Adapter/Libmemcached/OpenCest.php @@ -43,8 +43,11 @@ public function _before(IntegrationTester $I) public function sessionAdapterLibmemcachedOpen(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Libmemcached - open()'); + $adapter = $this->getSessionLibmemcached(); - $actual = $adapter->open('test', 'test1'); - $I->assertTrue($actual); + + $I->assertTrue( + $adapter->open('test', 'test1') + ); } } diff --git a/tests/integration/Session/Adapter/Libmemcached/ReadCest.php b/tests/integration/Session/Adapter/Libmemcached/ReadCest.php index f7f4ee2afaa..0a6b5abca0e 100644 --- a/tests/integration/Session/Adapter/Libmemcached/ReadCest.php +++ b/tests/integration/Session/Adapter/Libmemcached/ReadCest.php @@ -44,14 +44,20 @@ public function _before(IntegrationTester $I) public function sessionAdapterLibmemcachedRead(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Libmemcached - write()'); + $adapter = $this->getSessionLibmemcached(); - $value = serialize(uniqid()); + + $value = serialize( + uniqid() + ); $I->haveInLibmemcached('test1', $value); $expected = unserialize($value); $actual = $adapter->read('test1'); + $I->assertEquals($expected, $actual); + $I->removeFromLibmemcached('test1'); } } diff --git a/tests/integration/Session/Adapter/Libmemcached/WriteCest.php b/tests/integration/Session/Adapter/Libmemcached/WriteCest.php index 103d53188d2..ea647a8b515 100644 --- a/tests/integration/Session/Adapter/Libmemcached/WriteCest.php +++ b/tests/integration/Session/Adapter/Libmemcached/WriteCest.php @@ -45,15 +45,21 @@ public function _before(IntegrationTester $I) public function sessionAdapterLibmemcachedWrite(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Libmemcached - write()'); + $adapter = $this->getSessionLibmemcached(); $value = uniqid(); + $adapter->write('test1', $value); + + /** * Serialize the value because the adapter does not have a serializer */ $value = serialize($value); + $I->seeInLibmemcached('test1', $value); + $I->removeFromLibmemcached('test1'); } } diff --git a/tests/integration/Session/Adapter/Noop/CloseCest.php b/tests/integration/Session/Adapter/Noop/CloseCest.php index dd865a6b88f..dcd470ce248 100644 --- a/tests/integration/Session/Adapter/Noop/CloseCest.php +++ b/tests/integration/Session/Adapter/Noop/CloseCest.php @@ -43,8 +43,11 @@ public function _before(IntegrationTester $I) public function sessionAdapterNoopClose(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Noop - close()'); + $adapter = $this->getSessionNoop(); - $actual = $adapter->close(); - $I->assertTrue($actual); + + $I->assertTrue( + $adapter->close() + ); } } diff --git a/tests/integration/Session/Adapter/Noop/ConstructCest.php b/tests/integration/Session/Adapter/Noop/ConstructCest.php index 219a6bcc9d4..e4f333df8cd 100644 --- a/tests/integration/Session/Adapter/Noop/ConstructCest.php +++ b/tests/integration/Session/Adapter/Noop/ConstructCest.php @@ -44,8 +44,12 @@ public function _before(IntegrationTester $I) public function sessionAdapterNoopConstruct(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Noop - __construct()'); + $adapter = $this->getSessionNoop(); - $class = SessionHandlerInterface::class; - $I->assertInstanceOf($class, $adapter); + + $I->assertInstanceOf( + SessionHandlerInterface::class, + $adapter + ); } } diff --git a/tests/integration/Session/Adapter/Noop/DestroyCest.php b/tests/integration/Session/Adapter/Noop/DestroyCest.php index 9682ea62eb0..8ba595efdb7 100644 --- a/tests/integration/Session/Adapter/Noop/DestroyCest.php +++ b/tests/integration/Session/Adapter/Noop/DestroyCest.php @@ -43,9 +43,11 @@ public function _before(IntegrationTester $I) public function sessionAdapterNoopDestroy(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Noop - destroy()'); + $adapter = $this->getSessionNoop(); - $actual = $adapter->destroy('test1'); - $I->assertTrue($actual); + $I->assertTrue( + $adapter->destroy('test1') + ); } } diff --git a/tests/integration/Session/Adapter/Noop/GcCest.php b/tests/integration/Session/Adapter/Noop/GcCest.php index f5f65d15071..2fdb0b662fa 100644 --- a/tests/integration/Session/Adapter/Noop/GcCest.php +++ b/tests/integration/Session/Adapter/Noop/GcCest.php @@ -43,9 +43,11 @@ public function _before(IntegrationTester $I) public function sessionAdapterNoopGc(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Noop - gc()'); + $adapter = $this->getSessionNoop(); - $actual = $adapter->gc(1); - $I->assertTrue($actual); + $I->assertTrue( + $adapter->gc(1) + ); } } diff --git a/tests/integration/Session/Adapter/Noop/OpenCest.php b/tests/integration/Session/Adapter/Noop/OpenCest.php index 04411de35b9..403a4692300 100644 --- a/tests/integration/Session/Adapter/Noop/OpenCest.php +++ b/tests/integration/Session/Adapter/Noop/OpenCest.php @@ -43,8 +43,14 @@ public function _before(IntegrationTester $I) public function sessionAdapterNoopOpen(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Noop - open()'); + $adapter = $this->getSessionNoop(); - $actual = $adapter->open(cacheFolder(), 'test1'); - $I->assertTrue($actual); + + $I->assertTrue( + $adapter->open( + cacheFolder(), + 'test1' + ) + ); } } diff --git a/tests/integration/Session/Adapter/Noop/ReadCest.php b/tests/integration/Session/Adapter/Noop/ReadCest.php index 4929408d634..6a94065ae15 100644 --- a/tests/integration/Session/Adapter/Noop/ReadCest.php +++ b/tests/integration/Session/Adapter/Noop/ReadCest.php @@ -44,12 +44,15 @@ public function _before(IntegrationTester $I) public function sessionAdapterNoopRead(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Noop - write()'); + $adapter = $this->getSessionNoop(); $value = uniqid(); + $adapter->write('test1', $value); - $expected = ''; - $actual = $adapter->read('test1'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + '', + $adapter->read('test1') + ); } } diff --git a/tests/integration/Session/Adapter/Noop/WriteCest.php b/tests/integration/Session/Adapter/Noop/WriteCest.php index 08238399495..95cce56803b 100644 --- a/tests/integration/Session/Adapter/Noop/WriteCest.php +++ b/tests/integration/Session/Adapter/Noop/WriteCest.php @@ -44,7 +44,12 @@ public function _before(IntegrationTester $I) public function sessionAdapterNoopWrite(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Noop - write()'); + $adapter = $this->getSessionNoop(); - $adapter->write('test1', uniqid()); + + $adapter->write( + 'test1', + uniqid() + ); } } diff --git a/tests/integration/Session/Adapter/Redis/CloseCest.php b/tests/integration/Session/Adapter/Redis/CloseCest.php index 08d77fa799c..d7f4370151e 100644 --- a/tests/integration/Session/Adapter/Redis/CloseCest.php +++ b/tests/integration/Session/Adapter/Redis/CloseCest.php @@ -43,8 +43,11 @@ public function _before(IntegrationTester $I) public function sessionAdapterRedisClose(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Redis - close()'); + $adapter = $this->getSessionRedis(); - $actual = $adapter->close(); - $I->assertTrue($actual); + + $I->assertTrue( + $adapter->close() + ); } } diff --git a/tests/integration/Session/Adapter/Redis/ConstructCest.php b/tests/integration/Session/Adapter/Redis/ConstructCest.php index aa3e641ef91..44fa7eecd93 100644 --- a/tests/integration/Session/Adapter/Redis/ConstructCest.php +++ b/tests/integration/Session/Adapter/Redis/ConstructCest.php @@ -44,8 +44,12 @@ public function _before(IntegrationTester $I) public function sessionAdapterRedisConstruct(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Redis - __construct()'); + $adapter = $this->getSessionRedis(); - $class = SessionHandlerInterface::class; - $I->assertInstanceOf($class, $adapter); + + $I->assertInstanceOf( + SessionHandlerInterface::class, + $adapter + ); } } diff --git a/tests/integration/Session/Adapter/Redis/DestroyCest.php b/tests/integration/Session/Adapter/Redis/DestroyCest.php index 665f6edde15..8ce00fd3e03 100644 --- a/tests/integration/Session/Adapter/Redis/DestroyCest.php +++ b/tests/integration/Session/Adapter/Redis/DestroyCest.php @@ -44,13 +44,22 @@ public function _before(IntegrationTester $I) public function sessionAdapterRedisDestroy(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Redis - destroy()'); + $adapter = $this->getSessionRedis(); $value = uniqid(); $serialized = serialize($value); - $I->haveInRedis('string', 'test1', $serialized); - $actual = $adapter->destroy('test1'); - $I->assertTrue($actual); + + $I->haveInRedis( + 'string', + 'test1', + $serialized + ); + + $I->assertTrue( + $adapter->destroy('test1') + ); + $I->dontSeeInRedis('test1'); } } diff --git a/tests/integration/Session/Adapter/Redis/GcCest.php b/tests/integration/Session/Adapter/Redis/GcCest.php index 019b1cc2bdc..4a32fc05873 100644 --- a/tests/integration/Session/Adapter/Redis/GcCest.php +++ b/tests/integration/Session/Adapter/Redis/GcCest.php @@ -43,9 +43,11 @@ public function _before(IntegrationTester $I) public function sessionAdapterRedisGc(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Redis - gc()'); + $adapter = $this->getSessionRedis(); - $actual = $adapter->gc(1); - $I->assertTrue($actual); + $I->assertTrue( + $adapter->gc(1) + ); } } diff --git a/tests/integration/Session/Adapter/Redis/OpenCest.php b/tests/integration/Session/Adapter/Redis/OpenCest.php index b434121b2fa..2e80201e953 100644 --- a/tests/integration/Session/Adapter/Redis/OpenCest.php +++ b/tests/integration/Session/Adapter/Redis/OpenCest.php @@ -43,8 +43,11 @@ public function _before(IntegrationTester $I) public function sessionAdapterRedisOpen(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Redis - open()'); + $adapter = $this->getSessionRedis(); - $actual = $adapter->open('test', 'test1'); - $I->assertTrue($actual); + + $I->assertTrue( + $adapter->open('test', 'test1') + ); } } diff --git a/tests/integration/Session/Adapter/Redis/ReadCest.php b/tests/integration/Session/Adapter/Redis/ReadCest.php index 9d71a78ecb8..38f8bbf5b1d 100644 --- a/tests/integration/Session/Adapter/Redis/ReadCest.php +++ b/tests/integration/Session/Adapter/Redis/ReadCest.php @@ -44,14 +44,21 @@ public function _before(IntegrationTester $I) public function sessionAdapterRedisRead(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Redis - write()'); + $adapter = $this->getSessionRedis(); $value = uniqid(); - $I->haveInRedis('string', 'test1', $value); + $I->haveInRedis( + 'string', + 'test1', + $value + ); + + $I->assertEquals( + $value, + $adapter->read('test1') + ); - $expected = $value; - $actual = $adapter->read('test1'); - $I->assertEquals($expected, $actual); $I->sendCommandToRedis('del', 'test1'); } } diff --git a/tests/integration/Session/Adapter/Redis/WriteCest.php b/tests/integration/Session/Adapter/Redis/WriteCest.php index 0b3e5b5a778..8a19e03856e 100644 --- a/tests/integration/Session/Adapter/Redis/WriteCest.php +++ b/tests/integration/Session/Adapter/Redis/WriteCest.php @@ -44,16 +44,20 @@ public function _before(IntegrationTester $I) public function sessionAdapterRedisWrite(IntegrationTester $I) { $I->wantToTest('Session\Adapter\Redis - write()'); + $adapter = $this->getSessionRedis(); $value = uniqid(); + $adapter->write('test1', $value); /** * Serialize the value because the adapter does not have a serializer */ - $expected = $value; - $actual = $I->grabFromRedis('test1'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $value, + $I->grabFromRedis('test1') + ); + $I->sendCommandToRedis('del', 'test1'); } } diff --git a/tests/integration/Session/Bag/ClearCest.php b/tests/integration/Session/Bag/ClearCest.php index 38c70a2b41c..ce2cd404f7b 100644 --- a/tests/integration/Session/Bag/ClearCest.php +++ b/tests/integration/Session/Bag/ClearCest.php @@ -36,21 +36,27 @@ class ClearCest public function sessionBagClear(IntegrationTester $I) { $I->wantToTest('Session\Bag - clear()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Bag('BagTest'); + $collection->init($data); - $expected = $data; - $actual = $collection->toArray(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $data, + $collection->toArray() + ); $collection->clear(); - $expected = 0; - $actual = $collection->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $collection->count() + ); } } diff --git a/tests/integration/Session/Bag/ConstructCest.php b/tests/integration/Session/Bag/ConstructCest.php index 1d55ab71efb..afa40ea92c5 100644 --- a/tests/integration/Session/Bag/ConstructCest.php +++ b/tests/integration/Session/Bag/ConstructCest.php @@ -36,9 +36,12 @@ class ConstructCest public function sessionBagConstruct(IntegrationTester $I) { $I->wantToTest('Session\Bag - __construct()'); + $collection = new Bag('BagTest'); - $class = Bag::class; - $I->assertInstanceOf($class, $collection); + $I->assertInstanceOf( + Bag::class, + $collection + ); } } diff --git a/tests/integration/Session/Bag/CountCest.php b/tests/integration/Session/Bag/CountCest.php index fc53055a456..c2643aabde5 100644 --- a/tests/integration/Session/Bag/CountCest.php +++ b/tests/integration/Session/Bag/CountCest.php @@ -36,17 +36,25 @@ class CountCest public function sessionBagCount(IntegrationTester $I) { $I->wantToTest('Session\Bag - count()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Bag('BagTest'); + $collection->init($data); - $I->assertCount(3, $collection->toArray()); + $I->assertCount( + 3, + $collection->toArray() + ); - $actual = $collection->count(); - $I->assertEquals(3, $actual); + $I->assertEquals( + 3, + $collection->count() + ); } } diff --git a/tests/integration/Session/Bag/GetCest.php b/tests/integration/Session/Bag/GetCest.php index a61f3921c8c..87c96993f49 100644 --- a/tests/integration/Session/Bag/GetCest.php +++ b/tests/integration/Session/Bag/GetCest.php @@ -36,28 +36,40 @@ class GetCest public function sessionBagGet(IntegrationTester $I) { $I->wantToTest('Session\Bag - get()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Bag('BagTest'); + $collection->init($data); - $expected = 'four'; - $actual = $collection->get('three'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'four', + $collection->get('three') + ); - $actual = $collection->get('THREE'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'four', + $collection->get('THREE') + ); - $actual = $collection['three']; - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'four', + $collection['three'] + ); - $actual = $collection->three; - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'four', + $collection->three + ); - $actual = $collection->offsetGet('three'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'four', + $collection->offsetGet('three') + ); } } diff --git a/tests/integration/Session/Bag/GetIteratorCest.php b/tests/integration/Session/Bag/GetIteratorCest.php index e506f5b3b8a..4e7f33f7d1c 100644 --- a/tests/integration/Session/Bag/GetIteratorCest.php +++ b/tests/integration/Session/Bag/GetIteratorCest.php @@ -36,16 +36,22 @@ class GetIteratorCest public function sessionBagGetIterator(IntegrationTester $I) { $I->wantToTest('Session\Bag - getIterator()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Bag('BagTest'); + $collection->init($data); foreach ($collection as $key => $value) { - $I->assertEquals($data[$key], $collection[$key]); + $I->assertEquals( + $data[$key], + $collection[$key] + ); } } } diff --git a/tests/integration/Session/Bag/GetSetDICest.php b/tests/integration/Session/Bag/GetSetDICest.php index 9aeb9bcf42b..8651113cd12 100644 --- a/tests/integration/Session/Bag/GetSetDICest.php +++ b/tests/integration/Session/Bag/GetSetDICest.php @@ -37,9 +37,16 @@ class GetSetDICest public function sessionBagGetSetDI(IntegrationTester $I) { $I->wantToTest("Session\Bag - getDI()/setDI()"); + $session = new Bag("DiTest"); - $di = new FactoryDefault(); + + $di = new FactoryDefault(); + $session->setDI($di); - $I->assertEquals($di, $session->getDI()); + + $I->assertEquals( + $di, + $session->getDI() + ); } } diff --git a/tests/integration/Session/Bag/HasCest.php b/tests/integration/Session/Bag/HasCest.php index cbd993d3858..2313bfc428a 100644 --- a/tests/integration/Session/Bag/HasCest.php +++ b/tests/integration/Session/Bag/HasCest.php @@ -36,37 +36,47 @@ class HasCest public function sessionBagHas(IntegrationTester $I) { $I->wantToTest('Session\Bag - has()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; $collection = new Bag('BagTest'); + $collection->init($data); - $actual = $collection->has('three'); - $I->assertTrue($actual); + $I->assertTrue( + $collection->has('three') + ); - $actual = $collection->has('THREE'); - $I->assertTrue($actual); + $I->assertTrue( + $collection->has('THREE') + ); - $actual = $collection->has('THREE', false); - $I->assertFalse($actual); + $I->assertFalse( + $collection->has('THREE', false) + ); - $actual = $collection->has('unknown'); - $I->assertFalse($actual); + $I->assertFalse( + $collection->has('unknown') + ); - $actual = isset($collection['three']); - $I->assertTrue($actual); + $I->assertTrue( + isset($collection['three']) + ); - $actual = isset($collection['unknown']); - $I->assertFalse($actual); + $I->assertFalse( + isset($collection['unknown']) + ); - $actual = $collection->offsetExists('three'); - $I->assertTrue($actual); + $I->assertTrue( + $collection->offsetExists('three') + ); - $actual = $collection->offsetExists('unknown'); - $I->assertFalse($actual); + $I->assertFalse( + $collection->offsetExists('unknown') + ); } } diff --git a/tests/integration/Session/Bag/InitCest.php b/tests/integration/Session/Bag/InitCest.php index a44efba80fd..49986022a78 100644 --- a/tests/integration/Session/Bag/InitCest.php +++ b/tests/integration/Session/Bag/InitCest.php @@ -36,6 +36,7 @@ class InitCest public function sessionBagInit(IntegrationTester $I) { $I->wantToTest('Session\Bag - init()'); + $data = [ 'one' => 'two', 'three' => 'four', @@ -44,13 +45,16 @@ public function sessionBagInit(IntegrationTester $I) $collection = new Bag('BagTest'); - $expected = 0; - $actual = $collection->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 0, + $collection->count() + ); $collection->init($data); - $expected = $data; - $actual = $collection->toArray(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $data, + $collection->toArray() + ); } } diff --git a/tests/integration/Session/Bag/JsonSerializeCest.php b/tests/integration/Session/Bag/JsonSerializeCest.php index 7be49c7b9fc..afcef4d9eec 100644 --- a/tests/integration/Session/Bag/JsonSerializeCest.php +++ b/tests/integration/Session/Bag/JsonSerializeCest.php @@ -36,16 +36,20 @@ class JsonSerializeCest public function sessionBagJsonSerialize(IntegrationTester $I) { $I->wantToTest('Session\Bag - jsonSerialize()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Bag('BagTest'); + $collection->init($data); - $expected = $data; - $actual = $collection->jsonSerialize(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $data, + $collection->jsonSerialize() + ); } } diff --git a/tests/integration/Session/Bag/RemoveCest.php b/tests/integration/Session/Bag/RemoveCest.php index 4bc0a7b072a..1db0d6173c0 100644 --- a/tests/integration/Session/Bag/RemoveCest.php +++ b/tests/integration/Session/Bag/RemoveCest.php @@ -36,12 +36,15 @@ class RemoveCest public function sessionBagRemove(IntegrationTester $I) { $I->wantToTest('Session\Bag - remove()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Bag('BagTest'); + $collection->init($data); $expected = $data; @@ -75,6 +78,7 @@ public function sessionBagRemove(IntegrationTester $I) $collection->init($data); $collection->offsetUnset('five'); + $expected = [ 'one' => 'two', 'three' => 'four', diff --git a/tests/integration/Session/Bag/SerializeCest.php b/tests/integration/Session/Bag/SerializeCest.php index afcbd96eb36..61b46510182 100644 --- a/tests/integration/Session/Bag/SerializeCest.php +++ b/tests/integration/Session/Bag/SerializeCest.php @@ -36,16 +36,22 @@ class SerializeCest public function sessionBagSerialize(IntegrationTester $I) { $I->wantToTest('Session\Bag - serialize()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Bag('BagTest'); + $collection->init($data); + + $expected = serialize($data); $actual = $collection->serialize(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Session/Bag/SetCest.php b/tests/integration/Session/Bag/SetCest.php index ac7e69bf0f9..3355eca92ee 100644 --- a/tests/integration/Session/Bag/SetCest.php +++ b/tests/integration/Session/Bag/SetCest.php @@ -36,25 +36,42 @@ class SetCest public function sessionBagSet(IntegrationTester $I) { $I->wantToTest('Session\Bag - set()'); + $collection = new Bag('BagTest'); $collection->set('three', 'two'); + + + $expected = 'two'; $actual = $collection->get('three'); + $I->assertEquals($expected, $actual); + + $collection->three = 'Phalcon'; - $expected = 'Phalcon'; - $actual = $collection->get('three'); + + $expected = 'Phalcon'; + $actual = $collection->get('three'); + $I->assertEquals($expected, $actual); + + $collection->offsetSet('three', 123); + $expected = 123; $actual = $collection->get('three'); + $I->assertEquals($expected, $actual); + + $collection['three'] = true; - $actual = $collection->get('three'); - $I->assertTrue($actual); + + $I->assertTrue( + $collection->get('three') + ); } } diff --git a/tests/integration/Session/Bag/ToArrayCest.php b/tests/integration/Session/Bag/ToArrayCest.php index 8409e8f2414..feb2829e849 100644 --- a/tests/integration/Session/Bag/ToArrayCest.php +++ b/tests/integration/Session/Bag/ToArrayCest.php @@ -36,16 +36,22 @@ class ToArrayCest public function sessionBagToArray(IntegrationTester $I) { $I->wantToTest('Session\Bag - toArray()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Bag('BagTest'); + $collection->init($data); + + $expected = $data; $actual = $collection->toArray(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Session/Bag/ToJsonCest.php b/tests/integration/Session/Bag/ToJsonCest.php index aaafb596560..a0875563cf5 100644 --- a/tests/integration/Session/Bag/ToJsonCest.php +++ b/tests/integration/Session/Bag/ToJsonCest.php @@ -36,20 +36,29 @@ class ToJsonCest public function sessionBagToJson(IntegrationTester $I) { $I->wantToTest('Session\Bag - toJson()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Bag('BagTest'); + $collection->init($data); + + $expected = json_encode($data); $actual = $collection->toJson(); + $I->assertEquals($expected, $actual); + + $expected = json_encode($data, JSON_PRETTY_PRINT); $actual = $collection->toJson(JSON_PRETTY_PRINT); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Session/Bag/UnserializeCest.php b/tests/integration/Session/Bag/UnserializeCest.php index 797c43bf332..1827eebf068 100644 --- a/tests/integration/Session/Bag/UnserializeCest.php +++ b/tests/integration/Session/Bag/UnserializeCest.php @@ -36,17 +36,24 @@ class UnserializeCest public function sessionBagSerialize(IntegrationTester $I) { $I->wantToTest('Session\Bag - serialize()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $serialized = serialize($data); + $collection = new Bag('BagTest'); + + $collection->unserialize($serialized); + $expected = $data; $actual = $collection->toArray(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Session/Factory/LoadCest.php b/tests/integration/Session/Factory/LoadCest.php index f908125d0ae..498e09112bc 100644 --- a/tests/integration/Session/Factory/LoadCest.php +++ b/tests/integration/Session/Factory/LoadCest.php @@ -27,6 +27,7 @@ class LoadCest public function _before(IntegrationTester $I) { $I->skipTest('CHECKME'); + $this->init(); } @@ -41,6 +42,7 @@ public function _before(IntegrationTester $I) public function sessionFactoryLoadConfig(IntegrationTester $I) { $I->wantToTest("Session\Factory - load() - Config"); + $options = $this->config->session; $data = $options->toArray(); @@ -51,10 +53,18 @@ private function runTests(IntegrationTester $I, $options, array $data) { /** @var Memcache $session */ $session = Factory::load($options); + $I->assertInstanceOf(Files::class, $session); + + $expected = $session->getOptions(); - $actual = array_intersect_assoc($session->getOptions(), $data); + + $actual = array_intersect_assoc( + $session->getOptions(), + $data + ); + $I->assertEquals($expected, $actual); } @@ -69,6 +79,7 @@ private function runTests(IntegrationTester $I, $options, array $data) public function sessionFactoryLoadArray(IntegrationTester $I) { $I->wantToTest("Session\Factory - load() - array"); + $options = $this->arrayConfig['session']; $data = $options; diff --git a/tests/integration/Session/Manager/ConstructCest.php b/tests/integration/Session/Manager/ConstructCest.php index c2fa57713a8..c653d4e15a2 100644 --- a/tests/integration/Session/Manager/ConstructCest.php +++ b/tests/integration/Session/Manager/ConstructCest.php @@ -32,8 +32,12 @@ class ConstructCest public function sessionManagerConstruct(IntegrationTester $I) { $I->wantToTest('Session\Manager - __construct()'); + $manager = new Manager(); - $class = ManagerInterface::class; - $I->assertInstanceOf($class, $manager); + + $I->assertInstanceOf( + ManagerInterface::class, + $manager + ); } } diff --git a/tests/integration/Session/Manager/ExistsDestroyCest.php b/tests/integration/Session/Manager/ExistsDestroyCest.php index 79284398307..9a886aceacb 100644 --- a/tests/integration/Session/Manager/ExistsDestroyCest.php +++ b/tests/integration/Session/Manager/ExistsDestroyCest.php @@ -36,20 +36,26 @@ class ExistsDestroyCest public function sessionManagerExistsDestroy(IntegrationTester $I) { $I->wantToTest('Session\Manager - exists()/destroy()'); + $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); - $actual = $manager->start(); - $I->assertTrue($actual); + $I->assertTrue( + $manager->start() + ); - $actual = $manager->exists(); - $I->assertTrue($actual); + $I->assertTrue( + $manager->exists() + ); $manager->destroy(); - $actual = $manager->exists(); - $I->assertFalse($actual); + $I->assertFalse( + $manager->exists() + ); } /** @@ -66,24 +72,41 @@ public function sessionManagerExistsDestroy(IntegrationTester $I) public function sessionManagerDestroySuperGlobal(IntegrationTester $I) { $I->wantToTest('Session\Manager - destroy() - clean $_SESSION'); + $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); - $actual = $manager->start(); - $I->assertTrue($actual); - $actual = $manager->exists(); - $I->assertTrue($actual); + + $I->assertTrue( + $manager->start() + ); + + + + $I->assertTrue( + $manager->exists() + ); + + $manager->set('test1', __METHOD__); + $I->assertArrayHasKey('#test1', $_SESSION); + $I->assertContains(__METHOD__, $_SESSION['#test1']); + + $manager->destroy(); + $I->assertArrayNotHasKey('#test1', $_SESSION); - $actual = $manager->exists(); - $I->assertFalse($actual); + $I->assertFalse( + $manager->exists() + ); } } diff --git a/tests/integration/Session/Manager/GetSetCest.php b/tests/integration/Session/Manager/GetSetCest.php index 7dc8a7fc78c..1c363a7a0c6 100644 --- a/tests/integration/Session/Manager/GetSetCest.php +++ b/tests/integration/Session/Manager/GetSetCest.php @@ -36,21 +36,37 @@ class GetSetCest public function sessionManagerGetSet(IntegrationTester $I) { $I->wantToTest('Session\Manager - get()/set()'); + $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); - $actual = $manager->start(); - $I->assertTrue($actual); + + + $I->assertTrue( + $manager->start() + ); + + $expected = 'myval'; + $manager->set('test', $expected); + $actual = $manager->get('test'); + $I->assertEquals($expected, $actual); + + $manager->destroy(); - $actual = $manager->exists(); - $I->assertFalse($actual); + + + $I->assertFalse( + $manager->exists() + ); } } diff --git a/tests/integration/Session/Manager/GetSetDICest.php b/tests/integration/Session/Manager/GetSetDICest.php index 4ac5cf21c8a..ebce9ed05fc 100644 --- a/tests/integration/Session/Manager/GetSetDICest.php +++ b/tests/integration/Session/Manager/GetSetDICest.php @@ -32,9 +32,15 @@ class GetSetDICest public function sessionManagerGetSetDI(IntegrationTester $I) { $I->wantToTest('Session\Manager - getDI()/setDI()'); + $session = new Manager(); $container = new FactoryDefault(); + $session->setDI($container); - $I->assertEquals($container, $session->getDI()); + + $I->assertEquals( + $container, + $session->getDI() + ); } } diff --git a/tests/integration/Session/Manager/GetSetHandlerCest.php b/tests/integration/Session/Manager/GetSetHandlerCest.php index 0e3f0d3f2ad..f0976503477 100644 --- a/tests/integration/Session/Manager/GetSetHandlerCest.php +++ b/tests/integration/Session/Manager/GetSetHandlerCest.php @@ -37,12 +37,20 @@ class GetSetHandlerCest public function sessionManagerGetSetHandler(IntegrationTester $I) { $I->wantToTest('Session\Manager - getHandler()/setHandler()'); + $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); + + $actual = $manager->getHandler(); - $class = SessionHandlerInterface::class; - $I->assertInstanceOf($class, $actual); + + $I->assertInstanceOf( + SessionHandlerInterface::class, + $actual + ); } } diff --git a/tests/integration/Session/Manager/GetSetIdCest.php b/tests/integration/Session/Manager/GetSetIdCest.php index e376f920d1d..589663560be 100644 --- a/tests/integration/Session/Manager/GetSetIdCest.php +++ b/tests/integration/Session/Manager/GetSetIdCest.php @@ -37,19 +37,39 @@ class GetSetIdCest public function sessionManagerGetSetId(IntegrationTester $I) { $I->wantToTest('Session\Manager - getId()/setId()'); + $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); - $expected = ''; - $actual = $manager->getId(); - $I->assertEquals($expected, $actual); + + + $actual = $manager->getId(); + + $I->assertEquals( + '', + $actual + ); + + $id = uniqid(); + $manager->setId($id); - $expected = $id; - $actual = $manager->getId(); - $I->assertEquals($expected, $actual); + + + + $actual = $manager->getId(); + + $I->assertEquals( + $id, + $actual + ); + + + $manager->destroy(); } } diff --git a/tests/integration/Session/Manager/GetSetNameCest.php b/tests/integration/Session/Manager/GetSetNameCest.php index f2566cd496c..7b025e2626f 100644 --- a/tests/integration/Session/Manager/GetSetNameCest.php +++ b/tests/integration/Session/Manager/GetSetNameCest.php @@ -37,8 +37,11 @@ class GetSetNameCest public function sessionManagerGetSetName(IntegrationTester $I) { $I->wantToTest('Session\Manager - getName()/setName()'); + $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); if (false !== $manager->exists()) { @@ -46,9 +49,11 @@ public function sessionManagerGetSetName(IntegrationTester $I) } $manager->setName('myname'); - $expected = 'myname'; - $actual = $manager->getName(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 'myname', + $manager->getName() + ); } /** @@ -62,11 +67,14 @@ public function sessionManagerGetSetName(IntegrationTester $I) public function sessionManagerGetNameNotValidName(IntegrationTester $I) { $I->wantToTest('Session\Manager - getName()/setName() - not valid name'); + $I->expectThrowable( new InvalidArgumentException('The name contains non alphanum characters'), function () { $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); $manager->setName('%-gga34'); @@ -85,21 +93,22 @@ function () { public function sessionManagerGetNameSessionStarted(IntegrationTester $I) { $I->wantToTest('Session\Manager - getName()/setName() - session started'); - $valid = false; + $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); - try { - $manager->start(); - $manager->setName('%-gga34'); - } catch (InvalidArgumentException $ex) { - $manager->destroy(); - $valid = true; - $expected = 'Cannot set session name after a session has started'; - $actual = $ex->getMessage(); - $I->assertEquals($expected, $actual); - } - $I->assertTrue($valid); + $manager->start(); + + $I->expectThrowable( + new InvalidArgumentException('Cannot set session name after a session has started'), + function () use ($manager) { + $manager->setName('%-gga34'); + } + ); + + $manager->destroy(); } } diff --git a/tests/integration/Session/Manager/GetSetOptionsCest.php b/tests/integration/Session/Manager/GetSetOptionsCest.php index 6ed38767dd5..9fdcbd4717f 100644 --- a/tests/integration/Session/Manager/GetSetOptionsCest.php +++ b/tests/integration/Session/Manager/GetSetOptionsCest.php @@ -36,14 +36,19 @@ class GetSetOptionsCest public function sessionManagerGetSetOptionsConstructor(IntegrationTester $I) { $I->wantToTest('Session\Manager - getOptions()/setOptions() - constructor'); + $options = [ 'test1' => 'option1', 'test2' => 'option2', ]; $manager = new Manager($options); + + + $expected = $options; $actual = $manager->getOptions(); + $I->assertEquals($expected, $actual); } @@ -58,18 +63,25 @@ public function sessionManagerGetSetOptionsConstructor(IntegrationTester $I) public function sessionManagerGetSetOptions(IntegrationTester $I) { $I->wantToTest('Session\Manager - getOptions()/setOptions()'); + $options = [ 'test1' => 'option1', 'test2' => 'option2', ]; $manager = new Manager($options); + $options = [ 'test3' => 'option3', ]; + $manager->setOptions($options); - $expected = $options; - $actual = $manager->getOptions(); - $I->assertEquals($expected, $actual); + + + + $I->assertEquals( + $options, + $manager->getOptions() + ); } } diff --git a/tests/integration/Session/Manager/HasCest.php b/tests/integration/Session/Manager/HasCest.php index ac38e19e45a..d6f8eec87f4 100644 --- a/tests/integration/Session/Manager/HasCest.php +++ b/tests/integration/Session/Manager/HasCest.php @@ -36,23 +36,31 @@ class HasCest public function sessionManagerHas(IntegrationTester $I) { $I->wantToTest('Session\Manager - has()'); + $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); - $actual = $manager->start(); - $I->assertTrue($actual); + $I->assertTrue( + $manager->start() + ); - $actual = $manager->has('test'); - $I->assertFalse($actual); + $I->assertFalse( + $manager->has('test') + ); $manager->set('test', 'myval'); - $actual = $manager->has('test'); - $I->assertTrue($actual); + + $I->assertTrue( + $manager->has('test') + ); $manager->destroy(); - $actual = $manager->exists(); - $I->assertFalse($actual); + $I->assertFalse( + $manager->exists() + ); } } diff --git a/tests/integration/Session/Manager/RegenerateIdCest.php b/tests/integration/Session/Manager/RegenerateIdCest.php index dea3f7e782e..acc07235cc5 100644 --- a/tests/integration/Session/Manager/RegenerateIdCest.php +++ b/tests/integration/Session/Manager/RegenerateIdCest.php @@ -36,15 +36,27 @@ class RegenerateIdCest public function sessionManagerRegenerateId(IntegrationTester $I) { $I->wantToTest('Session\Manager - regenerateId()'); + $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); + $manager->start(); $current = $manager->getId(); + $manager->regenerateId(true); + + + $actual = $manager->getId(); + $I->assertNotEquals($current, $actual); + + + $manager->destroy(); } } diff --git a/tests/integration/Session/Manager/RemoveCest.php b/tests/integration/Session/Manager/RemoveCest.php index 1e71dbfe05a..42e976d4b0a 100644 --- a/tests/integration/Session/Manager/RemoveCest.php +++ b/tests/integration/Session/Manager/RemoveCest.php @@ -44,27 +44,36 @@ public function _after(IntegrationTester $I) public function sessionManagerRemove(IntegrationTester $I) { $I->wantToTest('Session\Manager - remove()'); + $manager = new Manager(); $files = $this->getSessionFiles(); + $manager->setHandler($files); - $actual = $manager->start(); - $I->assertTrue($actual); + $I->assertTrue( + $manager->start() + ); - $actual = $manager->has('test'); - $I->assertFalse($actual); + $I->assertFalse( + $manager->has('test') + ); $manager->set('test', 'myval'); - $actual = $manager->has('test'); - $I->assertTrue($actual); + + $I->assertTrue( + $manager->has('test') + ); $manager->remove('test'); - $actual = $manager->has('test'); - $I->assertFalse($actual); + + $I->assertFalse( + $manager->has('test') + ); $manager->destroy(); - $actual = $manager->exists(); - $I->assertFalse($actual); + $I->assertFalse( + $manager->exists() + ); } } diff --git a/tests/integration/Session/Manager/StatusCest.php b/tests/integration/Session/Manager/StatusCest.php index 59965f3808d..8687b7386c4 100644 --- a/tests/integration/Session/Manager/StatusCest.php +++ b/tests/integration/Session/Manager/StatusCest.php @@ -36,25 +36,32 @@ class StatusCest public function sessionManagerStatus(IntegrationTester $I) { $I->wantToTest('Session\Manager - status()'); + $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); - $expected = $manager::SESSION_NONE; - $actual = $manager->status(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $manager::SESSION_NONE, + $manager->status() + ); - $actual = $manager->start(); - $I->assertTrue($actual); + $I->assertTrue( + $manager->start() + ); - $expected = $manager::SESSION_ACTIVE; - $actual = $manager->status(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $manager::SESSION_ACTIVE, + $manager->status() + ); $manager->destroy(); - $expected = $manager::SESSION_NONE; - $actual = $manager->status(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $manager::SESSION_NONE, + $manager->status() + ); } } diff --git a/tests/integration/Session/Manager/UnderscoreGetSetCest.php b/tests/integration/Session/Manager/UnderscoreGetSetCest.php index 7413871c3b3..85048a240c7 100644 --- a/tests/integration/Session/Manager/UnderscoreGetSetCest.php +++ b/tests/integration/Session/Manager/UnderscoreGetSetCest.php @@ -36,21 +36,31 @@ class UnderscoreGetSetCest public function sessionManagerUnderscoreGetSet(IntegrationTester $I) { $I->wantToTest('Session\Manager - __get()/__set()'); + $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); - $actual = $manager->start(); - $I->assertTrue($actual); + $I->assertTrue( + $manager->start() + ); + + $expected = 'myval'; $manager->test = $expected; $actual = $manager->test; + $I->assertEquals($expected, $actual); + + $manager->destroy(); - $actual = $manager->exists(); - $I->assertFalse($actual); + $I->assertFalse( + $manager->exists() + ); } } diff --git a/tests/integration/Session/Manager/UnderscoreIssetCest.php b/tests/integration/Session/Manager/UnderscoreIssetCest.php index 8a015667c10..2cbacd07bd9 100644 --- a/tests/integration/Session/Manager/UnderscoreIssetCest.php +++ b/tests/integration/Session/Manager/UnderscoreIssetCest.php @@ -37,23 +37,31 @@ public function sessionManagerUnderscoreIsset(IntegrationTester $I) { $I->wantToTest('Session\Manager - __isset()'); $I->wantToTest('Session\Manager - has()'); + $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); - $actual = $manager->start(); - $I->assertTrue($actual); + $I->assertTrue( + $manager->start() + ); - $actual = isset($manager->test); - $I->assertFalse($actual); + $I->assertFalse( + isset($manager->test) + ); $manager->set('test', 'myval'); - $actual = isset($manager->test); - $I->assertTrue($actual); + + $I->assertTrue( + isset($manager->test) + ); $manager->destroy(); - $actual = $manager->exists(); - $I->assertFalse($actual); + $I->assertFalse( + $manager->exists() + ); } } diff --git a/tests/integration/Session/Manager/UnderscoreUnsetCest.php b/tests/integration/Session/Manager/UnderscoreUnsetCest.php index 12452dba4e8..392c6ff02d8 100644 --- a/tests/integration/Session/Manager/UnderscoreUnsetCest.php +++ b/tests/integration/Session/Manager/UnderscoreUnsetCest.php @@ -38,27 +38,37 @@ class UnderscoreUnsetCest public function sessionManagerUnderscoreUnset(IntegrationTester $I) { $I->wantToTest('Session\Manager - __unset()'); + $manager = new Manager(); - $files = $this->getSessionFiles(); + + $files = $this->getSessionFiles(); + $manager->setHandler($files); - $actual = $manager->start(); - $I->assertTrue($actual); + $I->assertTrue( + $manager->start() + ); - $actual = $manager->has('test'); - $I->assertFalse($actual); + $I->assertFalse( + $manager->has('test') + ); $manager->set('test', 'myval'); - $actual = $manager->has('test'); - $I->assertTrue($actual); + + $I->assertTrue( + $manager->has('test') + ); unset($manager->test); - $actual = $manager->has('test'); - $I->assertFalse($actual); + + $I->assertFalse( + $manager->has('test') + ); $manager->destroy(); - $actual = $manager->exists(); - $I->assertFalse($actual); + $I->assertFalse( + $manager->exists() + ); } } diff --git a/tests/integration/Url/GetCest.php b/tests/integration/Url/GetCest.php index 555bce6487f..f060793b2a7 100644 --- a/tests/integration/Url/GetCest.php +++ b/tests/integration/Url/GetCest.php @@ -31,23 +31,29 @@ class GetCest public function urlGet(IntegrationTester $I) { $I->wantToTest("Url - get()"); + $url = new Url(); $url->setBaseUri('https://phalconphp.com'); - $expected = 'https://phalconphp.com'; - $actual = $url->get(); - $I->assertEquals($expected, $actual); - - $actual = $url->get(''); - $I->assertEquals($expected, $actual); - - $expected = 'https://phalconphp.com/'; - $actual = $url->get('/'); - $I->assertEquals($expected, $actual); - - $expected = 'https://phalconphp.com/en/team'; - $actual = $url->get('/en/team'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'https://phalconphp.com', + $url->get() + ); + + $I->assertEquals( + 'https://phalconphp.com', + $url->get('') + ); + + $I->assertEquals( + 'https://phalconphp.com/', + $url->get('/') + ); + + $I->assertEquals( + 'https://phalconphp.com/en/team', + $url->get('/en/team') + ); } } diff --git a/tests/integration/Url/GetSetDICest.php b/tests/integration/Url/GetSetDICest.php index 14cbc412f6e..be6baa62940 100644 --- a/tests/integration/Url/GetSetDICest.php +++ b/tests/integration/Url/GetSetDICest.php @@ -34,16 +34,19 @@ class GetSetDICest public function urlGetSetDI(IntegrationTester $I) { $I->wantToTest("Url - getDI()/setDI()"); + $url = new Url(); $container = new Di(); $url->setDI($container); - $class = Di::class; $actual = $url->getDI(); - $I->assertInstanceOf($class, $actual); - $expected = $container; - $I->assertEquals($expected, $actual); + $I->assertInstanceOf( + Di::class, + $actual + ); + + $I->assertEquals($container, $actual); } } diff --git a/tests/integration/Url/GetSetStaticBaseUriCest.php b/tests/integration/Url/GetSetStaticBaseUriCest.php index 02fd652c767..a59f8015ada 100644 --- a/tests/integration/Url/GetSetStaticBaseUriCest.php +++ b/tests/integration/Url/GetSetStaticBaseUriCest.php @@ -33,14 +33,17 @@ class GetSetStaticBaseUriCest public function urlGetSetStaticBaseUri(IntegrationTester $I) { $I->wantToTest("Url - getStaticBaseUri()/setStaticBaseUri()"); + $url = new Url(); $path = 'https://phalconphp.com'; + $url->setStaticBaseUri($path); - $expected = $path; - $actual = $url->getStaticBaseUri(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $path, + $url->getStaticBaseUri() + ); } /** @@ -55,11 +58,15 @@ public function urlGetSetStaticBaseUri(IntegrationTester $I) public function urlGetSetStaticBaseUriGetBaseUri(IntegrationTester $I) { $I->wantToTest("Url - getStaticBaseUri()/setStaticBaseUri() - getBaseUri()"); + $url = new Url(); $expected = 'https://phalconphp.com'; + $url->setBaseUri($expected); + $actual = $url->getStaticBaseUri(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Validation/CombinedFieldsValidator/ConstructCest.php b/tests/integration/Validation/CombinedFieldsValidator/ConstructCest.php index 949c14e7b6b..8d9251afa94 100644 --- a/tests/integration/Validation/CombinedFieldsValidator/ConstructCest.php +++ b/tests/integration/Validation/CombinedFieldsValidator/ConstructCest.php @@ -30,6 +30,7 @@ class ConstructCest public function validationCombinedfieldsvalidatorConstruct(IntegrationTester $I) { $I->wantToTest('Validation\CombinedFieldsValidator - __construct()'); + $I->skipTest('Need implementation'); } } diff --git a/tests/integration/Validation/ValidationCest.php b/tests/integration/Validation/ValidationCest.php index 1200f6f7efc..16bb4bae0af 100644 --- a/tests/integration/Validation/ValidationCest.php +++ b/tests/integration/Validation/ValidationCest.php @@ -47,7 +47,9 @@ public function _before(IntegrationTester $I) { $this->setNewFactoryDefault(); $this->setDiMysql(); + $this->validation = new Validation(); + $this->validation->add( 'name', new PresenceOf( @@ -56,6 +58,7 @@ public function _before(IntegrationTester $I) ] ) ); + $this->validation->setFilters('name', 'trim'); } @@ -94,7 +97,11 @@ public function appendValidationMessageToTheNonObject(IntegrationTester $I) ), ] ); - $I->assertEquals($expectedMessages, $validation->getMessages()); + + $I->assertEquals( + $expectedMessages, + $validation->getMessages() + ); } /** @@ -105,13 +112,23 @@ public function appendValidationMessageToTheNonObject(IntegrationTester $I) */ public function testWithEntityAndFilter(IntegrationTester $I) { - $users = new Users([ - 'name' => ' ', - ]); + $users = new Users( + [ + 'name' => ' ', + ] + ); + $messages = $this->validation->validate(null, $users); - $I->assertEquals($messages->count(), 1); - $I->assertEquals($messages->offsetGet(0)->getMessage(), 'Name cant be empty.'); + $I->assertEquals( + 1, + $messages->count() + ); + + $I->assertEquals( + 'Name cant be empty.', + $messages->offsetGet(0)->getMessage() + ); $expectedMessages = new Messages( [ @@ -123,6 +140,7 @@ public function testWithEntityAndFilter(IntegrationTester $I) ), ] ); + $I->assertEquals($messages, $expectedMessages); } @@ -134,9 +152,11 @@ public function testWithEntityAndFilter(IntegrationTester $I) */ public function testFilteringEntity(IntegrationTester $I) { - $users = new Users([ - 'name' => 'SomeName ', - ]); + $users = new Users( + [ + 'name' => 'SomeName ', + ] + ); $this->validation->validate(null, $users); @@ -147,13 +167,18 @@ public function testGetDefaultValidationMessageShouldReturnEmptyStringIfNoneIsSe { $validation = new Validation(); - $I->assertIsEmpty($validation->getDefaultMessage('_notexistentvalidationmessage_')); + $I->assertIsEmpty( + $validation->getDefaultMessage('_notexistentvalidationmessage_') + ); } public function testValidationFiltering(IntegrationTester $I) { $validation = new Validation(); - $validation->setDI($this->container); + + $validation->setDI( + $this->container + ); $validation ->add('name', new PresenceOf([ @@ -167,7 +192,12 @@ public function testValidationFiltering(IntegrationTester $I) $validation->setFilters('name', 'trim'); $validation->setFilters('email', 'trim'); - $messages = $validation->validate(['name' => ' ', 'email' => ' ']); + $messages = $validation->validate( + [ + 'name' => ' ', + 'email' => ' ', + ] + ); $I->assertCount(2, $messages); @@ -181,6 +211,7 @@ public function testValidationFiltering(IntegrationTester $I) 0 ), ]; + $I->assertEquals($filtered, $expectedMessages); } @@ -196,6 +227,7 @@ public function testValidationSetLabels(IntegrationTester $I) ] ) ); + $validation->add( 'email', new Email( @@ -205,6 +237,7 @@ public function testValidationSetLabels(IntegrationTester $I) ] ) ); + $validation->add( 'firstname', new PresenceOf( @@ -213,6 +246,7 @@ public function testValidationSetLabels(IntegrationTester $I) ] ) ); + $validation->add( 'firstname', new StringLength( @@ -223,8 +257,17 @@ public function testValidationSetLabels(IntegrationTester $I) ) ); - $validation->setLabels(['firstname' => 'First name']); - $messages = $validation->validate(['email' => '', 'firstname' => '']); + $validation->setLabels( + [ + 'firstname' => 'First name', + ] + ); + + $messages = $validation->validate( + [ + 'email' => '', 'firstname' => '', + ] + ); $expectedMessages = new Messages( [ @@ -254,6 +297,7 @@ public function testValidationSetLabels(IntegrationTester $I) ), ] ); + $I->assertEquals($messages, $expectedMessages); } @@ -267,51 +311,93 @@ public function testEmptyValues(IntegrationTester $I) { $validation = new Validation(); - $validation->setDI($this->container); + $validation->setDI( + $this->container + ); $validation - ->add('name', new Alpha([ - 'message' => 'The name is not valid', - ])) - ->add('name', new PresenceOf([ - 'message' => 'The name is required', - ])) - ->add('url', new Url([ - 'message' => 'The url is not valid.', - 'allowEmpty' => true, - ])) - ->add('email', new Email([ - 'message' => 'The email is not valid.', - 'allowEmpty' => [null, false], - ])) + ->add( + 'name', + new Alpha( + [ + 'message' => 'The name is not valid', + ] + ) + ) + ->add( + 'name', + new PresenceOf( + [ + 'message' => 'The name is required', + ] + ) + ) + ->add( + 'url', + new Url( + [ + 'message' => 'The url is not valid.', + 'allowEmpty' => true, + ] + ) + ) + ->add( + 'email', + new Email( + [ + 'message' => 'The email is not valid.', + 'allowEmpty' => [null, false], + ] + ) + ) ; - $messages = $validation->validate([ - 'name' => '', - 'url' => null, - 'email' => '', - ]); + + + $messages = $validation->validate( + [ + 'name' => '', + 'url' => null, + 'email' => '', + ] + ); + $I->assertCount(2, $messages); - $messages = $validation->validate([ - 'name' => 'MyName', - 'url' => '', - 'email' => '', - ]); + + + $messages = $validation->validate( + [ + 'name' => 'MyName', + 'url' => '', + 'email' => '', + ] + ); + $I->assertCount(1, $messages); - $messages = $validation->validate([ - 'name' => 'MyName', - 'url' => false, - 'email' => null, - ]); + + + $messages = $validation->validate( + [ + 'name' => 'MyName', + 'url' => false, + 'email' => null, + ] + ); + $I->assertCount(0, $messages); - $messages = $validation->validate([ - 'name' => 'MyName', - 'url' => 0, - 'email' => 0, - ]); + + + $messages = $validation->validate( + [ + 'name' => 'MyName', + 'url' => 0, + 'email' => 0, + ] + ); + $I->assertCount(1, $messages); } } diff --git a/tests/integration/Validation/Validator/Alnum/ConstructCest.php b/tests/integration/Validation/Validator/Alnum/ConstructCest.php index 1bdd8a16afd..8ecc9ab7c5f 100644 --- a/tests/integration/Validation/Validator/Alnum/ConstructCest.php +++ b/tests/integration/Validation/Validator/Alnum/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorAlnumConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Alnum - __construct()'); + $validator = new Alnum(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Alnum/GetOptionCest.php b/tests/integration/Validation/Validator/Alnum/GetOptionCest.php index c0e352828fa..926ddf5ed41 100644 --- a/tests/integration/Validation/Validator/Alnum/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Alnum/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorAlnumGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Alnum - getOption()'); + $validator = new Alnum(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Alnum/HasOptionCest.php b/tests/integration/Validation/Validator/Alnum/HasOptionCest.php index 9e4e97a3405..e020a5f3ce9 100644 --- a/tests/integration/Validation/Validator/Alnum/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Alnum/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorAlnumHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Alnum - hasOption()'); - $validator = new Alnum(['message' => 'This is a message']); + + $validator = new Alnum( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Alnum/SetOptionCest.php b/tests/integration/Validation/Validator/Alnum/SetOptionCest.php index 0a9fe49da10..358fa0ee07d 100644 --- a/tests/integration/Validation/Validator/Alnum/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Alnum/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorAlnumSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Alnum - setOption()'); + $validator = new Alnum(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Alnum/ValidateCest.php b/tests/integration/Validation/Validator/Alnum/ValidateCest.php index f54f23fca66..946514e3362 100644 --- a/tests/integration/Validation/Validator/Alnum/ValidateCest.php +++ b/tests/integration/Validation/Validator/Alnum/ValidateCest.php @@ -32,19 +32,35 @@ class ValidateCest public function validationValidatorAlnumValidateSingleField(IntegrationTester $I) { $I->wantToTest("Validation\Validator\Alnum - validate() - single field"); + $validation = new Validation(); - $validation->add('name', new Alnum()); - $messages = $validation->validate(['name' => 'SomeValue123']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $validation->add( + 'name', + new Alnum() + ); + + $messages = $validation->validate( + [ + 'name' => 'SomeValue123', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); - $messages = $validation->validate(['name' => 'SomeValue123!@#']); + $messages = $validation->validate( + [ + 'name' => 'SomeValue123!@#', + ] + ); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + $messages->count() + ); } /** @@ -58,11 +74,14 @@ public function validationValidatorAlnumValidateSingleField(IntegrationTester $I public function validationValidatorAlnumValidateMultipleField(IntegrationTester $I) { $I->wantToTest("Validation\Validator\Alnum - validate() - multiple field"); - $validation = new Validation(); + + $validation = new Validation(); + $validationMessages = [ 'name' => 'Name must be alnum', 'type' => 'Type must be alnum', ]; + $validation->add( [ 'name', @@ -74,34 +93,56 @@ public function validationValidatorAlnumValidateMultipleField(IntegrationTester ] ) ); - $messages = $validation->validate(['name' => 'SomeValue123', 'type' => 'SomeValue123']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'name' => 'SomeValue123', + 'type' => 'SomeValue123', + ] + ); - $messages = $validation->validate(['name' => 'SomeValue123!@#', 'type' => 'SomeValue123']); + $I->assertEquals( + 0, + $messages->count() + ); + + $messages = $validation->validate( + [ + 'name' => 'SomeValue123!@#', + 'type' => 'SomeValue123', + ] + ); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + $messages->count() + ); - $expected = $validationMessages['name']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $validationMessages['name'], + $messages->offsetGet(0)->getMessage() + ); - $messages = $validation->validate(['name' => 'SomeValue123!@#', 'type' => 'SomeValue123!@#']); + $messages = $validation->validate( + [ + 'name' => 'SomeValue123!@#', + 'type' => 'SomeValue123!@#', + ] + ); - $expected = 2; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 2, + $messages->count() + ); - $expected = $validationMessages['name']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $validationMessages['name'], + $messages->offsetGet(0)->getMessage() + ); - $expected = $validationMessages['type']; - $actual = $messages->offsetGet(1)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $validationMessages['type'], + $messages->offsetGet(1)->getMessage() + ); } } diff --git a/tests/integration/Validation/Validator/Alpha/ConstructCest.php b/tests/integration/Validation/Validator/Alpha/ConstructCest.php index 6d21ca53816..46d2cc31fbb 100644 --- a/tests/integration/Validation/Validator/Alpha/ConstructCest.php +++ b/tests/integration/Validation/Validator/Alpha/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorAlphaConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Alpha - __construct()'); + $validator = new Alpha(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Alpha/GetOptionCest.php b/tests/integration/Validation/Validator/Alpha/GetOptionCest.php index b235654e15b..c26d1f9f3f9 100644 --- a/tests/integration/Validation/Validator/Alpha/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Alpha/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorAlphaGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Alpha - getOption()'); + $validator = new Alpha(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Alpha/HasOptionCest.php b/tests/integration/Validation/Validator/Alpha/HasOptionCest.php index a0c5491e97d..c681ff55b4e 100644 --- a/tests/integration/Validation/Validator/Alpha/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Alpha/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorAlphaHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Alpha - hasOption()'); - $validator = new Alpha(['message' => 'This is a message']); + + $validator = new Alpha( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Alpha/SetOptionCest.php b/tests/integration/Validation/Validator/Alpha/SetOptionCest.php index 3c99ab2c0d1..5a2c087456e 100644 --- a/tests/integration/Validation/Validator/Alpha/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Alpha/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorAlphaSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Alpha - setOption()'); + $validator = new Alpha(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Alpha/ValidateCest.php b/tests/integration/Validation/Validator/Alpha/ValidateCest.php index d4f47a020ec..8cd206be2b6 100644 --- a/tests/integration/Validation/Validator/Alpha/ValidateCest.php +++ b/tests/integration/Validation/Validator/Alpha/ValidateCest.php @@ -12,6 +12,7 @@ namespace Phalcon\Test\Integration\Validation\Validator\Alpha; +use Codeception\Example; use IntegrationTester; use Phalcon\Messages\Message; use Phalcon\Messages\Messages; @@ -34,18 +35,39 @@ class ValidateCest public function validationValidatorAlphaValidateSingleField(IntegrationTester $I) { $I->wantToTest("Validation\Validator\Alpha - validate() - single field"); + $validation = new Validation(); - $validation->add('name', new Alpha()); - $messages = $validation->validate(['name' => 'Asd']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $validation->add( + 'name', + new Alpha() + ); - $messages = $validation->validate(['name' => 'Asd123']); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + + $messages = $validation->validate( + [ + 'name' => 'Asd', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + + + + $messages = $validation->validate( + [ + 'name' => 'Asd123', + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); } /** @@ -59,41 +81,85 @@ public function validationValidatorAlphaValidateSingleField(IntegrationTester $I public function validationValidatorAlphaValidateMultipleField(IntegrationTester $I) { $I->wantToTest("Validation\Validator\Alpha - validate() - multiple field"); - $validation = new Validation(); + + $validation = new Validation(); + $validationMessages = [ 'name' => 'Name must be alpha.', 'type' => 'Type must by alpha.', ]; - $validation->add(['name', 'type'], new Alpha([ - 'message' => $validationMessages, - ])); - $messages = $validation->validate(['name' => 'Asd', 'type' => 'Asd']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['name' => 'Asd123', 'type' => 'Asd']); + $validation->add( + ['name', 'type'], + new Alpha( + [ + 'message' => $validationMessages, + ] + ) + ); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $expected = $validationMessages['name']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['name' => 'Asd123', 'type' => 'Asd123']); - $expected = 2; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'name' => 'Asd', + 'type' => 'Asd', + ] + ); - $expected = $validationMessages['name']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 0, + $messages->count() + ); - $expected = $validationMessages['type']; - $actual = $messages->offsetGet(1)->getMessage(); - $I->assertEquals($expected, $actual); + + + $messages = $validation->validate( + [ + 'name' => 'Asd123', + 'type' => 'Asd', + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); + + + + $I->assertEquals( + $validationMessages['name'], + $messages->offsetGet(0)->getMessage() + ); + + + + $messages = $validation->validate( + [ + 'name' => 'Asd123', + 'type' => 'Asd123', + ] + ); + + $I->assertEquals( + 2, + $messages->count() + ); + + + + $I->assertEquals( + $validationMessages['name'], + $messages->offsetGet(0)->getMessage() + ); + + + + $I->assertEquals( + $validationMessages['type'], + $messages->offsetGet(1)->getMessage() + ); } /** @@ -104,43 +170,56 @@ public function validationValidatorAlphaValidateMultipleField(IntegrationTester * * @author Phalcon Team * @since 2016-06-10 + * + * @dataProvider validationValidatorAlphaValidateNonAlphabeticCharactersProvider */ - public function validationValidatorAlphaValidateNonAlphabeticCharacters(IntegrationTester $I) + public function validationValidatorAlphaValidateNonAlphabeticCharacters(IntegrationTester $I, Example $example) { $I->wantToTest("Validation\Validator\Alpha - validate() - non alphabetic characters"); - $examples = [ - '1', - 123, - 'a-b-c-d', - 'a-1-c-2', - 'a1c2', - 'o0o0o0o0', - ]; - foreach ($examples as $input) { - $validation = new Validation; - $validation->add( - 'name', - new Alpha( - [ - 'message' => ':field must contain only letters', - ] - ) - ); - - $expected = new Messages( + $input = $example[0]; + + $validation = new Validation; + + $validation->add( + 'name', + new Alpha( [ - new Message( - 'name must contain only letters', - 'name', - 'Alpha', - 0 - ), + 'message' => ':field must contain only letters', ] - ); - $actual = $validation->validate(['name' => $input]); - $I->assertEquals($expected, $actual); - } + ) + ); + + $expected = new Messages( + [ + new Message( + 'name must contain only letters', + 'name', + 'Alpha', + 0 + ), + ] + ); + + $actual = $validation->validate( + [ + 'name' => $input, + ] + ); + + $I->assertEquals($expected, $actual); + } + + private function validationValidatorAlphaValidateNonAlphabeticCharactersProvider(): array + { + return [ + ['1'], + [123], + ['a-b-c-d'], + ['a-1-c-2'], + ['a1c2'], + ['o0o0o0o0'], + ]; } /** @@ -151,35 +230,47 @@ public function validationValidatorAlphaValidateNonAlphabeticCharacters(Integrat * * @author Phalcon Team * @since 2016-06-10 + * + * @dataProvider validationValidatorAlphaValidateAlphabeticCharactersProvider */ - public function validationValidatorAlphaValidateAlphabeticCharacters(IntegrationTester $I) + public function validationValidatorAlphaValidateAlphabeticCharacters(IntegrationTester $I, Example $example) { $I->wantToTest("Validation\Validator\Alpha - validate() - alphabetic characters"); - $examples = [ - 'a', - 'asdavafaiwnoabwiubafpowf', - 'QWERTYUIOPASDFGHJKL', - 'aSdFgHjKl', - null, - ]; - foreach ($examples as $input) { - $validation = new Validation; - $validation->add( - 'name', - new Alpha( - [ - 'message' => ':field must contain only letters', - ] - ) - ); - - $messages = $validation->validate(['name' => $input]); - - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - } + $input = $example[0]; + + $validation = new Validation; + + $validation->add( + 'name', + new Alpha( + [ + 'message' => ':field must contain only letters', + ] + ) + ); + + $messages = $validation->validate( + [ + 'name' => $input, + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + } + + private function validationValidatorAlphaValidateAlphabeticCharactersProvider(): array + { + return [ + ['a'], + ['asdavafaiwnoabwiubafpowf'], + ['QWERTYUIOPASDFGHJKL'], + ['aSdFgHjKl'], + [null], + ]; } /** @@ -190,38 +281,50 @@ public function validationValidatorAlphaValidateAlphabeticCharacters(Integration * * @author Phalcon Team * @since 2016-06-10 + * + * @dataProvider validationValidatorAlphaValidateNonLatinCharactersProvider */ - public function validationValidatorAlphaValidateNonLatinCharacters(IntegrationTester $I) + public function validationValidatorAlphaValidateNonLatinCharacters(IntegrationTester $I, Example $example) { $I->wantToTest("Validation\Validator\Alpha - validate() - non latin characters"); - $examples = [ - 'йцукенг', - 'ждлорпа', - 'Señor', - 'cocoñùт', - 'COCOÑÙТ', - 'JÄGER', - 'šš', - 'あいうえお', - '零一二三四五', - ]; - foreach ($examples as $input) { - $validation = new Validation; - $validation->add( - 'name', - new Alpha( - [ - 'message' => ':field must contain only letters', - ] - ) - ); - - $messages = $validation->validate(['name' => $input]); - - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - } + $input = $example[0]; + + $validation = new Validation; + + $validation->add( + 'name', + new Alpha( + [ + 'message' => ':field must contain only letters', + ] + ) + ); + + $messages = $validation->validate( + [ + 'name' => $input, + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + } + + private function validationValidatorAlphaValidateNonLatinCharactersProvider(): array + { + return [ + ['йцукенг'], + ['ждлорпа'], + ['Señor'], + ['cocoñùт'], + ['COCOÑÙТ'], + ['JÄGER'], + ['šš'], + ['あいうえお'], + ['零一二三四五'], + ]; } } diff --git a/tests/integration/Validation/Validator/Between/ConstructCest.php b/tests/integration/Validation/Validator/Between/ConstructCest.php index cc4dd2b1904..c5a2725ae07 100644 --- a/tests/integration/Validation/Validator/Between/ConstructCest.php +++ b/tests/integration/Validation/Validator/Between/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorBetweenConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Between - __construct()'); + $validator = new Between(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Between/GetOptionCest.php b/tests/integration/Validation/Validator/Between/GetOptionCest.php index 18ccadb27f1..4acc228b63f 100644 --- a/tests/integration/Validation/Validator/Between/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Between/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorBetweenGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Between - getOption()'); + $validator = new Between(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Between/HasOptionCest.php b/tests/integration/Validation/Validator/Between/HasOptionCest.php index f1d478bc771..7843b939fda 100644 --- a/tests/integration/Validation/Validator/Between/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Between/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorBetweenHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Between - hasOption()'); - $validator = new Between(['message' => 'This is a message']); + + $validator = new Between( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Between/SetOptionCest.php b/tests/integration/Validation/Validator/Between/SetOptionCest.php index e1795cb5bc0..bbcc27c86ef 100644 --- a/tests/integration/Validation/Validator/Between/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Between/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorBetweenSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Between - setOption()'); + $validator = new Between(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Between/ValidateCest.php b/tests/integration/Validation/Validator/Between/ValidateCest.php index c812c1a2cea..0789ab28607 100644 --- a/tests/integration/Validation/Validator/Between/ValidateCest.php +++ b/tests/integration/Validation/Validator/Between/ValidateCest.php @@ -34,7 +34,9 @@ class ValidateCest public function validationValidatorBetweenValidateSingleField(IntegrationTester $I) { $I->wantToTest("Validation\Validator\Between - validate() - single field"); + $validation = new Validation(); + $validation->add( 'price', new Between( @@ -45,7 +47,13 @@ public function validationValidatorBetweenValidateSingleField(IntegrationTester ) ); - $messages = $validation->validate(['price' => 5]); + + + $messages = $validation->validate( + [ + 'price' => 5, + ] + ); $expected = new Messages( [ @@ -57,18 +65,29 @@ public function validationValidatorBetweenValidateSingleField(IntegrationTester ), ] ); - $actual = $messages; - $I->assertEquals($expected, $actual); - $messages = $validation->validate([]); - $actual = $messages; - $I->assertEquals($expected, $actual); + $I->assertEquals($expected, $messages); - $messages = $validation->validate(['price' => 2]); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $messages = $validation->validate( + [] + ); + + $I->assertEquals($expected, $messages); + + + + $messages = $validation->validate( + [ + 'price' => 2, + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); } /** @@ -82,11 +101,14 @@ public function validationValidatorBetweenValidateSingleField(IntegrationTester public function validationValidatorBetweenValidateMultipleField(IntegrationTester $I) { $I->wantToTest("Validation\Validator\Between - validate() - multiple field"); - $validation = new Validation(); + + $validation = new Validation(); + $validationMessages = [ 'amount' => 'Amount must be between 0 and 999.', 'price' => 'Price must be between 0 and 999.', ]; + $validation->add( [ 'amount', @@ -107,35 +129,61 @@ public function validationValidatorBetweenValidateMultipleField(IntegrationTeste ) ); - $messages = $validation->validate(['amount' => 100]); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['amount' => 1000, 'price' => 100]); + $messages = $validation->validate( + [ + 'amount' => 100, + ] + ); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 0, + $messages->count() + ); - $expected = $validationMessages['amount']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['amount' => 1000, 'price' => 1000]); - $expected = 2; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'amount' => 1000, + 'price' => 100, + ] + ); - $expected = $validationMessages['amount']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + $messages->count() + ); - $expected = $validationMessages['price']; - $actual = $messages->offsetGet(1)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $validationMessages['amount'], + $messages->offsetGet(0)->getMessage() + ); + + + + $messages = $validation->validate( + [ + 'amount' => 1000, + 'price' => 1000, + ] + ); + + $I->assertEquals( + 2, + $messages->count() + ); + + $I->assertEquals( + $validationMessages['amount'], + $messages->offsetGet(0)->getMessage() + ); + + $I->assertEquals( + $validationMessages['price'], + $messages->offsetGet(1)->getMessage() + ); } /** @@ -149,6 +197,7 @@ public function validationValidatorBetweenValidateMultipleField(IntegrationTeste public function validationValidatorBetweenValidateCustomMessage(IntegrationTester $I) { $I->wantToTest("Validation\Validator\Between - validate() - custom message"); + $validation = new Validation(); $validation->add( @@ -162,7 +211,13 @@ public function validationValidatorBetweenValidateCustomMessage(IntegrationTeste ) ); - $messages = $validation->validate(['price' => 5]); + + + $messages = $validation->validate( + [ + 'price' => 5, + ] + ); $expected = new Messages( [ @@ -174,17 +229,27 @@ public function validationValidatorBetweenValidateCustomMessage(IntegrationTeste ), ] ); - $actual = $messages; - $I->assertEquals($expected, $actual); - $messages = $validation->validate([]); - $actual = $messages; + $actual = $messages; + $I->assertEquals($expected, $actual); - $messages = $validation->validate(['price' => 2]); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $validation->validate([]), + $messages + ); + + $messages = $validation->validate( + [ + 'price' => 2, + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); } } diff --git a/tests/integration/Validation/Validator/Callback/ConstructCest.php b/tests/integration/Validation/Validator/Callback/ConstructCest.php index f5691a34816..052dceb1ea7 100644 --- a/tests/integration/Validation/Validator/Callback/ConstructCest.php +++ b/tests/integration/Validation/Validator/Callback/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorCallbackConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Callback - __construct()'); + $validator = new Callback(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Callback/GetOptionCest.php b/tests/integration/Validation/Validator/Callback/GetOptionCest.php index 6ca4a0afc5d..b912a6341cd 100644 --- a/tests/integration/Validation/Validator/Callback/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Callback/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorCallbackGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Callback - getOption()'); + $validator = new Callback(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Callback/HasOptionCest.php b/tests/integration/Validation/Validator/Callback/HasOptionCest.php index 9cdb37df201..67fb84c1853 100644 --- a/tests/integration/Validation/Validator/Callback/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Callback/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorCallbackHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Callback - hasOption()'); - $validator = new Callback(['message' => 'This is a message']); + + $validator = new Callback( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Callback/SetOptionCest.php b/tests/integration/Validation/Validator/Callback/SetOptionCest.php index 7ef2466d2d7..4ff6aa7b6b2 100644 --- a/tests/integration/Validation/Validator/Callback/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Callback/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorCallbackSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Callback - setOption()'); + $validator = new Callback(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Callback/ValidateCest.php b/tests/integration/Validation/Validator/Callback/ValidateCest.php index 3e0225f7b4a..07a94affc19 100644 --- a/tests/integration/Validation/Validator/Callback/ValidateCest.php +++ b/tests/integration/Validation/Validator/Callback/ValidateCest.php @@ -37,8 +37,12 @@ class ValidateCest */ public function validationValidatorCallbackValidateSingleFieldBoolean(IntegrationTester $I) { - $I->wantToTest("Validation\Validator\Callback - validate() - single field using boolean"); + $I->wantToTest( + "Validation\Validator\Callback - validate() - single field using boolean" + ); + $validation = new Validation(); + $validation->add( 'user', new Callback( @@ -52,21 +56,40 @@ public function validationValidatorCallbackValidateSingleFieldBoolean(Integratio ) ); - $messages = $validation->validate(["user" => "user", "admin" => null]); - $expected = 0; - $actual = count($messages); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(["user" => null, "admin" => "admin"]); - $expected = 0; - $actual = count($messages); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + "user" => "user", + "admin" => null, + ] + ); + + $I->assertCount(0, $messages); + + + + $messages = $validation->validate( + [ + "user" => null, + "admin" => "admin", + ] + ); + + $I->assertCount(0, $messages); + + + + $messages = $validation->validate( + [ + "user" => "user", + "admin" => "admin", + ] + ); + + $I->assertCount(1, $messages); + - $messages = $validation->validate(["user" => "user", "admin" => "admin"]); - $expected = 1; - $actual = count($messages); - $I->assertEquals($expected, $actual); $expected = new Messages( [ @@ -78,8 +101,8 @@ public function validationValidatorCallbackValidateSingleFieldBoolean(Integratio ), ] ); - $actual = $messages; - $I->assertEquals($expected, $actual); + + $I->assertEquals($expected, $messages); } /** @@ -93,8 +116,12 @@ public function validationValidatorCallbackValidateSingleFieldBoolean(Integratio */ public function validationValidatorCallbackValidateSingleFieldValidator(IntegrationTester $I) { - $I->wantToTest("Validation\Validator\Callback - validate() - single field using validator"); + $I->wantToTest( + "Validation\Validator\Callback - validate() - single field using validator" + ); + $validation = new Validation(); + $validation->add( 'user', new Callback( @@ -114,23 +141,41 @@ public function validationValidatorCallbackValidateSingleFieldValidator(Integrat ] ) ); - $messages = $validation->validate(['user' => 'u', 'admin' => 'admin']); - $expected = 0; - $actual = count($messages); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['user' => 'user', 'admin' => null]); - $expected = 0; - $actual = count($messages); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'user' => 'u', + 'admin' => 'admin', + ] + ); + + $I->assertCount(0, $messages); + + + + $messages = $validation->validate( + [ + 'user' => 'user', + 'admin' => null, + ] + ); + + $I->assertCount(0, $messages); + + + + $messages = $validation->validate( + [ + 'user' => 'u', + 'admin' => null, + ] + ); + + $I->assertCount(1, $messages); - $messages = $validation->validate(['user' => 'u', 'admin' => null]); - $expected = 1; - $actual = count($messages); - $I->assertEquals($expected, $actual); $expected = new Messages( [ @@ -142,7 +187,9 @@ public function validationValidatorCallbackValidateSingleFieldValidator(Integrat ), ] ); - $actual = $messages; + + $actual = $messages; + $I->assertEquals($expected, $actual); } @@ -157,8 +204,12 @@ public function validationValidatorCallbackValidateSingleFieldValidator(Integrat */ public function validationValidatorCallbackValidateMultipleFieldBoolean(IntegrationTester $I) { - $I->wantToTest("Validation\Validator\Callback - validate() - multiple field returning boolean"); + $I->wantToTest( + "Validation\Validator\Callback - validate() - multiple field returning boolean" + ); + $validation = new Validation(); + $validation->add( ['user', 'admin'], new Callback( @@ -175,22 +226,40 @@ public function validationValidatorCallbackValidateMultipleFieldBoolean(Integrat ) ); - $messages = $validation->validate(['user' => null, 'admin' => 'admin']); - $expected = 0; - $actual = count($messages); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['user' => 'user', 'admin' => null]); + $messages = $validation->validate( + [ + 'user' => null, + 'admin' => 'admin', + ] + ); + + $I->assertCount(0, $messages); + + + + $messages = $validation->validate( + [ + 'user' => 'user', + 'admin' => null, + ] + ); + + $I->assertCount(0, $messages); + + + + $messages = $validation->validate( + [ + 'user' => 'user', + 'admin' => 'admin', + ] + ); + + $I->assertCount(2, $messages); - $expected = 0; - $actual = count($messages); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['user' => 'user', 'admin' => 'admin']); - $expected = 2; - $actual = count($messages); - $I->assertEquals($expected, $actual); $expected = new Messages( [ @@ -208,8 +277,8 @@ public function validationValidatorCallbackValidateMultipleFieldBoolean(Integrat ), ] ); - $actual = $messages; - $I->assertEquals($expected, $actual); + + $I->assertEquals($expected, $messages); } /** @@ -224,7 +293,9 @@ public function validationValidatorCallbackValidateMultipleFieldBoolean(Integrat public function validationValidatorCallbackValidateMultipleFieldValidator(IntegrationTester $I) { $I->wantToTest("Validation\Validator\Callback - validate() - multiple field validator"); + $validation = new Validation(); + $validation->add( ['user', 'admin'], new Callback( @@ -249,11 +320,18 @@ public function validationValidatorCallbackValidateMultipleFieldValidator(Integr ) ); - $messages = $validation->validate(['admin' => null, 'user' => null]); - $expected = 2; - $actual = count($messages); - $I->assertEquals($expected, $actual); + + $messages = $validation->validate( + [ + 'admin' => null, + 'user' => null, + ] + ); + + $I->assertCount(2, $messages); + + $expected = new Messages( [ @@ -271,23 +349,43 @@ public function validationValidatorCallbackValidateMultipleFieldValidator(Integr ), ] ); - $actual = $messages; - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['admin' => 'admin', 'user' => null]); - $expected = 0; - $actual = count($messages); - $I->assertEquals($expected, $actual); + $I->assertEquals($expected, $messages); + + + + $messages = $validation->validate( + [ + 'admin' => 'admin', + 'user' => null, + ] + ); + + $I->assertCount(0, $messages); + + + + $messages = $validation->validate( + [ + 'admin' => null, + 'user' => 'user', + ] + ); + + $I->assertCount(0, $messages); + + + + $messages = $validation->validate( + [ + 'admin' => 'admin', + 'user' => 'user', + ] + ); + + $I->assertCount(2, $messages); - $messages = $validation->validate(['admin' => null, 'user' => 'user']); - $expected = 0; - $actual = count($messages); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['admin' => 'admin', 'user' => 'user']); - $expected = 2; - $actual = count($messages); - $I->assertEquals($expected, $actual); $expected = new Messages( [ @@ -305,8 +403,8 @@ public function validationValidatorCallbackValidateMultipleFieldValidator(Integr ), ] ); - $actual = $messages; - $I->assertEquals($expected, $actual); + + $I->assertEquals($expected, $messages); } /** @@ -319,11 +417,15 @@ public function validationValidatorCallbackValidateMultipleFieldValidator(Integr */ public function validationValidatorCallbackValidateException(IntegrationTester $I) { - $I->wantToTest("Validation\Validator\Callback - validate() - exception"); + $I->wantToTest( + "Validation\Validator\Callback - validate() - exception" + ); + $I->expectThrowable( new Exception('Callback must return bool or Phalcon\Validation\Validator object'), function () { $validation = new Validation(); + $validation->add( 'user', new Callback( @@ -335,7 +437,11 @@ function () { ) ); - $validation->validate(['user' => 'user']); + $validation->validate( + [ + 'user' => 'user', + ] + ); } ); } diff --git a/tests/integration/Validation/Validator/Confirmation/ConstructCest.php b/tests/integration/Validation/Validator/Confirmation/ConstructCest.php index b89ed20a544..5279da1d622 100644 --- a/tests/integration/Validation/Validator/Confirmation/ConstructCest.php +++ b/tests/integration/Validation/Validator/Confirmation/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorConfirmationConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Confirmation - __construct()'); + $validator = new Confirmation(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Confirmation/GetOptionCest.php b/tests/integration/Validation/Validator/Confirmation/GetOptionCest.php index 05e48dff403..9e308cf8b8d 100644 --- a/tests/integration/Validation/Validator/Confirmation/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Confirmation/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorConfirmationGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Confirmation - getOption()'); + $validator = new Confirmation(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Confirmation/HasOptionCest.php b/tests/integration/Validation/Validator/Confirmation/HasOptionCest.php index b38555ecffb..fd37d9bd0e5 100644 --- a/tests/integration/Validation/Validator/Confirmation/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Confirmation/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorConfirmationHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Confirmation - hasOption()'); - $validator = new Confirmation(['message' => 'This is a message']); + + $validator = new Confirmation( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Confirmation/SetOptionCest.php b/tests/integration/Validation/Validator/Confirmation/SetOptionCest.php index 35f62830c30..dcd60119aa3 100644 --- a/tests/integration/Validation/Validator/Confirmation/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Confirmation/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorConfirmationSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Confirmation - setOption()'); + $validator = new Confirmation(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Confirmation/ValidateCest.php b/tests/integration/Validation/Validator/Confirmation/ValidateCest.php index 14adc22e0e8..296b28ed081 100644 --- a/tests/integration/Validation/Validator/Confirmation/ValidateCest.php +++ b/tests/integration/Validation/Validator/Confirmation/ValidateCest.php @@ -34,8 +34,12 @@ class ValidateCest */ public function validationValidatorConfirmationValidateSingleField(IntegrationTester $I) { - $I->wantToTest("Validation\Validator\Confirmation - validate() - single field"); + $I->wantToTest( + "Validation\Validator\Confirmation - validate() - single field" + ); + $validation = new Validation(); + $validation->add( 'name', new Confirmation( @@ -45,6 +49,8 @@ public function validationValidatorConfirmationValidateSingleField(IntegrationTe ) ); + + $messages = $validation->validate( [ 'name' => 'SomeValue', @@ -52,9 +58,12 @@ public function validationValidatorConfirmationValidateSingleField(IntegrationTe ] ); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 0, + $messages->count() + ); + + $messages = $validation->validate( [ @@ -63,9 +72,10 @@ public function validationValidatorConfirmationValidateSingleField(IntegrationTe ] ); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + $messages->count() + ); } /** @@ -79,12 +89,17 @@ public function validationValidatorConfirmationValidateSingleField(IntegrationTe */ public function validationValidatorConfirmationValidateMultipleField(IntegrationTester $I) { - $I->wantToTest("Validation\Validator\Confirmation - validate() - multiple field"); - $validation = new Validation(); + $I->wantToTest( + "Validation\Validator\Confirmation - validate() - multiple field" + ); + + $validation = new Validation(); + $validationMessages = [ 'name' => 'Name must be same as nameWith.', 'type' => 'Type must be same as typeWith.', ]; + $validation->add( ['name', 'type'], new Confirmation( @@ -98,6 +113,8 @@ public function validationValidatorConfirmationValidateMultipleField(Integration ) ); + + $messages = $validation->validate( [ 'name' => 'SomeValue', @@ -107,9 +124,12 @@ public function validationValidatorConfirmationValidateMultipleField(Integration ] ); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 0, + $messages->count() + ); + + $messages = $validation->validate( [ @@ -120,13 +140,17 @@ public function validationValidatorConfirmationValidateMultipleField(Integration ] ); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + $messages->count() + ); + + $I->assertEquals( + $validationMessages['name'], + $messages->offsetGet(0)->getMessage() + ); + - $expected = $validationMessages['name']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); $messages = $validation->validate( [ @@ -137,17 +161,20 @@ public function validationValidatorConfirmationValidateMultipleField(Integration ] ); - $expected = 2; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 2, + $messages->count() + ); - $expected = $validationMessages['name']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $validationMessages['name'], + $messages->offsetGet(0)->getMessage() + ); - $expected = $validationMessages['type']; - $actual = $messages->offsetGet(1)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $validationMessages['type'], + $messages->offsetGet(1)->getMessage() + ); } /** @@ -162,6 +189,7 @@ public function validationValidatorConfirmationValidateMultipleField(Integration public function validationValidatorConfirmationValidateEmptyValues(IntegrationTester $I) { $I->wantToTest("Validation\Validator\Confirmation - validate() - empty value"); + $expected = new Messages( [ new Message( @@ -174,6 +202,7 @@ public function validationValidatorConfirmationValidateEmptyValues(IntegrationTe ); $validation = new Validation(); + $validation->add( 'password', new Confirmation( @@ -184,6 +213,8 @@ public function validationValidatorConfirmationValidateEmptyValues(IntegrationTe ) ); + + $messages = $validation->validate( [ 'password' => 'test123', @@ -191,8 +222,12 @@ public function validationValidatorConfirmationValidateEmptyValues(IntegrationTe ] ); - $actual = $messages->count(); - $I->assertEquals(0, $actual); + $I->assertEquals( + 0, + $messages->count() + ); + + $messages = $validation->validate( [ @@ -201,10 +236,15 @@ public function validationValidatorConfirmationValidateEmptyValues(IntegrationTe ] ); - $actual = $messages->count(); - $I->assertEquals(0, $actual); + $I->assertEquals( + 0, + $messages->count() + ); + + $validation = new Validation(); + $validation->add( 'password', new Confirmation( @@ -215,6 +255,8 @@ public function validationValidatorConfirmationValidateEmptyValues(IntegrationTe ) ); + + $messages = $validation->validate( [ 'password' => 'test123', @@ -222,8 +264,12 @@ public function validationValidatorConfirmationValidateEmptyValues(IntegrationTe ] ); - $actual = $messages->count(); - $I->assertEquals(0, $actual); + $I->assertEquals( + 0, + $messages->count() + ); + + $messages = $validation->validate( [ @@ -232,12 +278,17 @@ public function validationValidatorConfirmationValidateEmptyValues(IntegrationTe ] ); - $actual = $messages->count(); - $I->assertEquals(1, $actual); - $actual = $messages; - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + $messages->count() + ); + + $I->assertEquals($expected, $messages); + + $validation = new Validation(); + $validation->add( 'password', new Confirmation( @@ -247,6 +298,8 @@ public function validationValidatorConfirmationValidateEmptyValues(IntegrationTe ) ); + + $messages = $validation->validate( [ 'password' => 'test123', @@ -254,8 +307,12 @@ public function validationValidatorConfirmationValidateEmptyValues(IntegrationTe ] ); - $actual = $messages->count(); - $I->assertEquals(0, $actual); + $I->assertEquals( + 0, + $messages->count() + ); + + $messages = $validation->validate( [ @@ -264,9 +321,11 @@ public function validationValidatorConfirmationValidateEmptyValues(IntegrationTe ] ); - $actual = $messages->count(); - $I->assertEquals(1, $actual); - $actual = $messages; - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + $messages->count() + ); + + $I->assertEquals($expected, $messages); } } diff --git a/tests/integration/Validation/Validator/CreditCard/ConstructCest.php b/tests/integration/Validation/Validator/CreditCard/ConstructCest.php index a97e38974d7..4ca56d702fb 100644 --- a/tests/integration/Validation/Validator/CreditCard/ConstructCest.php +++ b/tests/integration/Validation/Validator/CreditCard/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorCreditCardConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\CreditCard - __construct()'); + $validator = new CreditCard(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/CreditCard/GetOptionCest.php b/tests/integration/Validation/Validator/CreditCard/GetOptionCest.php index bae57c61931..366518e350b 100644 --- a/tests/integration/Validation/Validator/CreditCard/GetOptionCest.php +++ b/tests/integration/Validation/Validator/CreditCard/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorCreditCardGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\CreditCard - getOption()'); + $validator = new CreditCard(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/CreditCard/HasOptionCest.php b/tests/integration/Validation/Validator/CreditCard/HasOptionCest.php index d97e462d144..1fbb53a9c88 100644 --- a/tests/integration/Validation/Validator/CreditCard/HasOptionCest.php +++ b/tests/integration/Validation/Validator/CreditCard/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorCreditCardHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\CreditCard - hasOption()'); - $validator = new CreditCard(['message' => 'This is a message']); + + $validator = new CreditCard( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/CreditCard/SetOptionCest.php b/tests/integration/Validation/Validator/CreditCard/SetOptionCest.php index 1b7109c0092..7d32856fff4 100644 --- a/tests/integration/Validation/Validator/CreditCard/SetOptionCest.php +++ b/tests/integration/Validation/Validator/CreditCard/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorCreditCardSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\CreditCard - setOption()'); + $validator = new CreditCard(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/CreditCard/ValidateCest.php b/tests/integration/Validation/Validator/CreditCard/ValidateCest.php index 83ece78bdba..f1b165898ce 100644 --- a/tests/integration/Validation/Validator/CreditCard/ValidateCest.php +++ b/tests/integration/Validation/Validator/CreditCard/ValidateCest.php @@ -35,16 +35,31 @@ class ValidateCest public function validationValidatorCreditCardValidateSingleField(IntegrationTester $I) { $I->wantToTest("Validation\Validator\CreditCard - validate() - single"); + $validation = new Validation(); - $validation->add('creditCard', new CreditCard()); - $expected = 0; - $actual = count($validation->validate(['creditCard' => 4601587377626131])); - $I->assertEquals($expected, $actual); + $validation->add( + 'creditCard', + new CreditCard() + ); + + $I->assertCount( + 0, + $validation->validate( + [ + 'creditCard' => 4601587377626131, + ] + ) + ); - $expected = 1; - $actual = count($validation->validate(['creditCard' => 46015873776261312])); - $I->assertEquals($expected, $actual); + $I->assertCount( + 1, + $validation->validate( + [ + 'creditCard' => 46015873776261312, + ] + ) + ); } /** @@ -59,6 +74,7 @@ public function validationValidatorCreditCardValidateSingleField(IntegrationTest public function validationValidatorCreditCardValidateMultipleFields(IntegrationTester $I) { $I->wantToTest("Validation\Validator\CreditCard - validate() - multiple"); + $validation = new Validation(); $validationMessages = [ @@ -75,6 +91,8 @@ public function validationValidatorCreditCardValidateMultipleFields(IntegrationT ) ); + + $messages = $validation->validate( [ 'creditCard' => 4601587377626131, @@ -82,9 +100,12 @@ public function validationValidatorCreditCardValidateMultipleFields(IntegrationT ] ); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 0, + $messages->count() + ); + + $messages = $validation->validate( [ @@ -93,13 +114,19 @@ public function validationValidatorCreditCardValidateMultipleFields(IntegrationT ] ); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + $messages->count() + ); + + + + $I->assertEquals( + $validationMessages['creditCard'], + $messages->offsetGet(0)->getMessage() + ); + - $expected = $validationMessages['creditCard']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); $messages = $validation->validate( [ @@ -108,17 +135,24 @@ public function validationValidatorCreditCardValidateMultipleFields(IntegrationT ] ); - $expected = 2; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 2, + $messages->count() + ); + + + + $I->assertEquals( + $validationMessages['creditCard'], + $messages->offsetGet(0)->getMessage() + ); + - $expected = $validationMessages['creditCard']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); - $expected = $validationMessages['anotherCreditCard']; - $actual = $messages->offsetGet(1)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $validationMessages['anotherCreditCard'], + $messages->offsetGet(1)->getMessage() + ); } /** @@ -133,6 +167,7 @@ public function validationValidatorCreditCardValidateMultipleFields(IntegrationT public function validationValidatorCreditCardValidateValidCreditCard(IntegrationTester $I) { $I->wantToTest("Validation\Validator\CreditCard - validate() - valid card"); + $providers = [ 'amex' => '378282246310005', 'visa' => '4012888888881881', @@ -143,11 +178,20 @@ public function validationValidatorCreditCardValidateValidCreditCard(Integration foreach ($providers as $number) { $validation = new Validation(); - $validation->add('creditCard', new CreditCard()); - $expected = 0; - $actual = count($validation->validate(['creditCard' => $number])); - $I->assertEquals($expected, $actual); + $validation->add( + 'creditCard', + new CreditCard() + ); + + $I->assertCount( + 0, + $validation->validate( + [ + 'creditCard' => $number, + ] + ) + ); } } @@ -163,6 +207,7 @@ public function validationValidatorCreditCardValidateValidCreditCard(Integration public function validationValidatorCreditCardValidateInvalidCreditCard(IntegrationTester $I) { $I->wantToTest("Validation\Validator\CreditCard - validate() - invalid card"); + $cards = [ '1203191201121221', '102030102320', @@ -173,7 +218,13 @@ public function validationValidatorCreditCardValidateInvalidCreditCard(Integrati foreach ($cards as $number) { $validation = new Validation(); - $validation->add('creditCard', new CreditCard()); + + $validation->add( + 'creditCard', + new CreditCard() + ); + + $expected = new Messages( [ @@ -185,7 +236,13 @@ public function validationValidatorCreditCardValidateInvalidCreditCard(Integrati ), ] ); - $actual = $validation->validate(['creditCard' => $number]); + + $actual = $validation->validate( + [ + 'creditCard' => $number, + ] + ); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Validation/Validator/Date/ConstructCest.php b/tests/integration/Validation/Validator/Date/ConstructCest.php index 82ab63cd3bd..61f6148a6fd 100644 --- a/tests/integration/Validation/Validator/Date/ConstructCest.php +++ b/tests/integration/Validation/Validator/Date/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorDateConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Date - __construct()'); + $validator = new Date(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Date/GetOptionCest.php b/tests/integration/Validation/Validator/Date/GetOptionCest.php index 5f26a180d80..e71135dbd80 100644 --- a/tests/integration/Validation/Validator/Date/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Date/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorDateGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Date - getOption()'); + $validator = new Date(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Date/HasOptionCest.php b/tests/integration/Validation/Validator/Date/HasOptionCest.php index 160eb20c5bc..f8b40511229 100644 --- a/tests/integration/Validation/Validator/Date/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Date/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorDateHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Date - hasOption()'); - $validator = new Date(['message' => 'This is a message']); + + $validator = new Date( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Date/SetOptionCest.php b/tests/integration/Validation/Validator/Date/SetOptionCest.php index 43a9513c267..9084f9534c1 100644 --- a/tests/integration/Validation/Validator/Date/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Date/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorDateSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Date - setOption()'); + $validator = new Date(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Date/ValidateCest.php b/tests/integration/Validation/Validator/Date/ValidateCest.php index b78617331db..a2cdd3b1ab9 100644 --- a/tests/integration/Validation/Validator/Date/ValidateCest.php +++ b/tests/integration/Validation/Validator/Date/ValidateCest.php @@ -30,6 +30,7 @@ class ValidateCest public function validationValidatorDateValidate(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Date - validate()'); + $I->skipTest('Need implementation'); } } diff --git a/tests/integration/Validation/Validator/DateCest.php b/tests/integration/Validation/Validator/DateCest.php index e84ba3b2e72..14c4d184a29 100644 --- a/tests/integration/Validation/Validator/DateCest.php +++ b/tests/integration/Validation/Validator/DateCest.php @@ -28,17 +28,37 @@ class DateCest public function validationValidatorSingleField(IntegrationTester $I) { $validation = new Validation(); - $validation->add('date', new Date()); - $messages = $validation->validate(['date' => '2016-06-05']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $validation->add( + 'date', + new Date() + ); - $messages = $validation->validate(['date' => '2016-06-32']); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + + $messages = $validation->validate( + [ + 'date' => '2016-06-05', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + + + + $messages = $validation->validate( + [ + 'date' => '2016-06-32', + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); } /** @@ -49,7 +69,8 @@ public function validationValidatorSingleField(IntegrationTester $I) */ public function validationValidatorMultipleField(IntegrationTester $I) { - $validation = new Validation(); + $validation = new Validation(); + $validationMessages = [ 'date' => 'Date must be correct date format Y-m-d.', 'anotherDate' => 'AnotherDate must be correct date format d-m-Y.', @@ -68,24 +89,45 @@ public function validationValidatorMultipleField(IntegrationTester $I) ) ); - $messages = $validation->validate(['date' => '2016-06-05', 'anotherDate' => '05-06-2017']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'date' => '2016-06-05', + 'anotherDate' => '05-06-2017', + ] + ); - $messages = $validation->validate(['date' => '2016-06-32', 'anotherDate' => '05-06-2017']); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 0, + $messages->count() + ); + + $messages = $validation->validate( + [ + 'date' => '2016-06-32', + 'anotherDate' => '05-06-2017', + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); $expected = $validationMessages['date']; $actual = $messages->offsetGet(0)->getMessage(); $I->assertEquals($expected, $actual); - $messages = $validation->validate(['date' => '2016-06-32', 'anotherDate' => '32-06-2017']); - $expected = 2; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'date' => '2016-06-32', + 'anotherDate' => '32-06-2017', + ] + ); + + $I->assertEquals( + 2, + $messages->count() + ); $expected = $validationMessages['date']; $actual = $messages->offsetGet(0)->getMessage(); @@ -112,15 +154,30 @@ public function shouldDetectValidDates(IntegrationTester $I) ]; foreach ($dates as $item) { - $date = $item[0]; - $format = $item[1]; + $date = $item[0]; + $format = $item[1]; + $validation = new Validation(); - $validation->add('date', new Date(['format' => $format])); - $messages = $validation->validate(['date' => $date]); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $validation->add( + 'date', + new Date( + [ + 'format' => $format, + ] + ) + ); + + $messages = $validation->validate( + [ + 'date' => $date, + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); } } @@ -144,10 +201,19 @@ public function shouldDetectInvalidDates(IntegrationTester $I) ]; foreach ($dates as $item) { - $date = $item[0]; - $format = $item[1]; + $date = $item[0]; + $format = $item[1]; + $validation = new Validation(); - $validation->add('date', new Date(['format' => $format])); + + $validation->add( + 'date', + new Date( + [ + 'format' => $format, + ] + ) + ); $expected = new Messages( [ @@ -159,7 +225,13 @@ public function shouldDetectInvalidDates(IntegrationTester $I) ), ] ); - $actual = $validation->validate(['date' => $date]); + + $actual = $validation->validate( + [ + 'date' => $date, + ] + ); + $I->assertEquals($expected, $actual); } } diff --git a/tests/integration/Validation/Validator/Digit/ConstructCest.php b/tests/integration/Validation/Validator/Digit/ConstructCest.php index 0f96fc2d31c..97daf373dbe 100644 --- a/tests/integration/Validation/Validator/Digit/ConstructCest.php +++ b/tests/integration/Validation/Validator/Digit/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorDigitConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Digit - __construct()'); + $validator = new Digit(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Digit/GetOptionCest.php b/tests/integration/Validation/Validator/Digit/GetOptionCest.php index 4178f36fbe7..d195990e3c1 100644 --- a/tests/integration/Validation/Validator/Digit/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Digit/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorDigitGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Digit - getOption()'); + $validator = new Digit(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Digit/HasOptionCest.php b/tests/integration/Validation/Validator/Digit/HasOptionCest.php index 5fb383368c6..8ef3e865610 100644 --- a/tests/integration/Validation/Validator/Digit/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Digit/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorDigitHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Digit - hasOption()'); - $validator = new Digit(['message' => 'This is a message']); + + $validator = new Digit( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Digit/SetOptionCest.php b/tests/integration/Validation/Validator/Digit/SetOptionCest.php index 3de15580e22..24e83c68f37 100644 --- a/tests/integration/Validation/Validator/Digit/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Digit/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorDigitSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Digit - setOption()'); + $validator = new Digit(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Digit/ValidateCest.php b/tests/integration/Validation/Validator/Digit/ValidateCest.php index 8a58b3bbbb2..fb8aba4c296 100644 --- a/tests/integration/Validation/Validator/Digit/ValidateCest.php +++ b/tests/integration/Validation/Validator/Digit/ValidateCest.php @@ -30,6 +30,7 @@ class ValidateCest public function validationValidatorDigitValidate(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Digit - validate()'); + $I->skipTest('Need implementation'); } } diff --git a/tests/integration/Validation/Validator/DigitCest.php b/tests/integration/Validation/Validator/DigitCest.php index 2973f4d82a8..d1ae57adb2b 100644 --- a/tests/integration/Validation/Validator/DigitCest.php +++ b/tests/integration/Validation/Validator/DigitCest.php @@ -11,6 +11,7 @@ namespace Phalcon\Test\Integration\Validation\Validator; +use Codeception\Example; use IntegrationTester; use Phalcon\Validation; use Phalcon\Validation\Validator\Digit; @@ -26,17 +27,37 @@ class DigitCest public function validationValidatorSingleField(IntegrationTester $I) { $validation = new Validation(); - $validation->add('amount', new Digit()); - $messages = $validation->validate(['amount' => '123']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $validation->add( + 'amount', + new Digit() + ); + + + + $messages = $validation->validate( + [ + 'amount' => '123', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + + + + $messages = $validation->validate( + [ + 'amount' => '123abc', + ] + ); - $messages = $validation->validate(['amount' => '123abc']); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + $messages->count() + ); } /** @@ -47,11 +68,13 @@ public function validationValidatorSingleField(IntegrationTester $I) */ public function validationValidatorMultipleField(IntegrationTester $I) { - $validation = new Validation(); + $validation = new Validation(); + $validationMessages = [ 'amount' => 'Amount must be digit.', 'price' => 'Price must be digit.', ]; + $validation->add( ['amount', 'price'], new Digit( @@ -61,56 +84,102 @@ public function validationValidatorMultipleField(IntegrationTester $I) ) ); - $messages = $validation->validate(['amount' => '123', 'price' => '123']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['amount' => '123abc', 'price' => '123']); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $expected = $validationMessages['amount']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'amount' => '123', + 'price' => '123', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + + + + $messages = $validation->validate( + [ + 'amount' => '123abc', + 'price' => '123', + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); + + $I->assertEquals( + $validationMessages['amount'], + $messages->offsetGet(0)->getMessage() + ); + - $messages = $validation->validate(['amount' => '123abc', 'price' => '123abc']); - $expected = 2; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $expected = $validationMessages['amount']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'amount' => '123abc', + 'price' => '123abc', + ] + ); + + $I->assertEquals( + 2, + $messages->count() + ); - $expected = $validationMessages['price']; - $actual = $messages->offsetGet(1)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $validationMessages['amount'], + $messages->offsetGet(0)->getMessage() + ); + + $I->assertEquals( + $validationMessages['price'], + $messages->offsetGet(1)->getMessage() + ); } - public function validationValidatorShouldValidateIntOrStringOfDigits(IntegrationTester $I) + /** + * @dataProvider shouldValidateIntOrStringOfDigitsProvider + */ + public function validationValidatorShouldValidateIntOrStringOfDigits(IntegrationTester $I, Example $example) { - $examples = [ - '123', - 123, - PHP_INT_MAX, - 0xFFFFFF, - 100000, - -100000, - 0, - "0", - "00001233422003400", - ]; + $digit = $example[0]; + + $validation = new Validation(); - foreach ($examples as $digit) { - $validation = new Validation(); - $validation->add('amount', new Digit()); + $validation->add( + 'amount', + new Digit() + ); + + $messages = $validation->validate( + [ + 'amount' => $digit, + ] + ); - $messages = $validation->validate(['amount' => $digit]); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - } + $I->assertEquals( + 0, + $messages->count() + ); + } + + private function shouldValidateIntOrStringOfDigitsProvider() + { + return [ + ['123'], + [123], + [PHP_INT_MAX], + [0xFFFFFF], + [100000], + [-100000], + [0], + ["0"], + ["00001233422003400"], + ]; } } diff --git a/tests/integration/Validation/Validator/Email/ConstructCest.php b/tests/integration/Validation/Validator/Email/ConstructCest.php index 1f891e121be..d61a3b37f67 100644 --- a/tests/integration/Validation/Validator/Email/ConstructCest.php +++ b/tests/integration/Validation/Validator/Email/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorEmailConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Email - __construct()'); + $validator = new Email(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Email/GetOptionCest.php b/tests/integration/Validation/Validator/Email/GetOptionCest.php index d5b05526f77..8bb0a2bdc94 100644 --- a/tests/integration/Validation/Validator/Email/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Email/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorEmailGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Email - getOption()'); + $validator = new Email(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Email/HasOptionCest.php b/tests/integration/Validation/Validator/Email/HasOptionCest.php index d06a35176b0..f5229127480 100644 --- a/tests/integration/Validation/Validator/Email/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Email/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorEmailHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Email - hasOption()'); - $validator = new Email(['message' => 'This is a message']); + + $validator = new Email( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Email/SetOptionCest.php b/tests/integration/Validation/Validator/Email/SetOptionCest.php index 4fa7fd2cba9..707cc3b5ba8 100644 --- a/tests/integration/Validation/Validator/Email/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Email/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorEmailSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Email - setOption()'); + $validator = new Email(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Email/ValidateCest.php b/tests/integration/Validation/Validator/Email/ValidateCest.php index dfd1e3a5341..5ff3b2e8c17 100644 --- a/tests/integration/Validation/Validator/Email/ValidateCest.php +++ b/tests/integration/Validation/Validator/Email/ValidateCest.php @@ -30,6 +30,7 @@ class ValidateCest public function validationValidatorEmailValidate(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Email - validate()'); + $I->skipTest('Need implementation'); } } diff --git a/tests/integration/Validation/Validator/ExclusionIn/ConstructCest.php b/tests/integration/Validation/Validator/ExclusionIn/ConstructCest.php index 1fc1ec6e516..8017e5c5af2 100644 --- a/tests/integration/Validation/Validator/ExclusionIn/ConstructCest.php +++ b/tests/integration/Validation/Validator/ExclusionIn/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorExclusionInConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\ExclusionIn - __construct()'); + $validator = new ExclusionIn(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/ExclusionIn/GetOptionCest.php b/tests/integration/Validation/Validator/ExclusionIn/GetOptionCest.php index abd113032a4..cbb5caa5ce6 100644 --- a/tests/integration/Validation/Validator/ExclusionIn/GetOptionCest.php +++ b/tests/integration/Validation/Validator/ExclusionIn/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorExclusionInGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\ExclusionIn - getOption()'); + $validator = new ExclusionIn(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/ExclusionIn/HasOptionCest.php b/tests/integration/Validation/Validator/ExclusionIn/HasOptionCest.php index 71fca9b759e..cfd75816e12 100644 --- a/tests/integration/Validation/Validator/ExclusionIn/HasOptionCest.php +++ b/tests/integration/Validation/Validator/ExclusionIn/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorExclusionInHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\ExclusionIn - hasOption()'); - $validator = new ExclusionIn(['message' => 'This is a message']); + + $validator = new ExclusionIn( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/ExclusionIn/SetOptionCest.php b/tests/integration/Validation/Validator/ExclusionIn/SetOptionCest.php index d25e74e90e1..8766145e1fc 100644 --- a/tests/integration/Validation/Validator/ExclusionIn/SetOptionCest.php +++ b/tests/integration/Validation/Validator/ExclusionIn/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorExclusionInSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\ExclusionIn - setOption()'); + $validator = new ExclusionIn(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/ExclusionIn/ValidateCest.php b/tests/integration/Validation/Validator/ExclusionIn/ValidateCest.php index 28f47e17165..37f5d93f5b4 100644 --- a/tests/integration/Validation/Validator/ExclusionIn/ValidateCest.php +++ b/tests/integration/Validation/Validator/ExclusionIn/ValidateCest.php @@ -30,6 +30,7 @@ class ValidateCest public function validationValidatorExclusioninValidate(IntegrationTester $I) { $I->wantToTest('Validation\Validator\ExclusionIn - validate()'); + $I->skipTest('Need implementation'); } } diff --git a/tests/integration/Validation/Validator/File/ConstructCest.php b/tests/integration/Validation/Validator/File/ConstructCest.php index 259dca4d797..834088ebbfd 100644 --- a/tests/integration/Validation/Validator/File/ConstructCest.php +++ b/tests/integration/Validation/Validator/File/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorFileConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\File - __construct()'); + $validator = new File(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/File/GetOptionCest.php b/tests/integration/Validation/Validator/File/GetOptionCest.php index 2bdb366402d..044407c25a9 100644 --- a/tests/integration/Validation/Validator/File/GetOptionCest.php +++ b/tests/integration/Validation/Validator/File/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorFileGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\File - getOption()'); + $validator = new File(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/File/HasOptionCest.php b/tests/integration/Validation/Validator/File/HasOptionCest.php index a1958203716..201a5507545 100644 --- a/tests/integration/Validation/Validator/File/HasOptionCest.php +++ b/tests/integration/Validation/Validator/File/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorFileHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\File - hasOption()'); - $validator = new File(['message' => 'This is a message']); + + $validator = new File( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/File/SetOptionCest.php b/tests/integration/Validation/Validator/File/SetOptionCest.php index 8a29b8201c4..9338c46b94b 100644 --- a/tests/integration/Validation/Validator/File/SetOptionCest.php +++ b/tests/integration/Validation/Validator/File/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorFileSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\File - setOption()'); + $validator = new File(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/File/ValidateCest.php b/tests/integration/Validation/Validator/File/ValidateCest.php index 98ceb543b31..e9e7bf3e778 100644 --- a/tests/integration/Validation/Validator/File/ValidateCest.php +++ b/tests/integration/Validation/Validator/File/ValidateCest.php @@ -30,6 +30,7 @@ class ValidateCest public function validationValidatorFileValidate(IntegrationTester $I) { $I->wantToTest('Validation\Validator\File - validate()'); + $I->skipTest('Need implementation'); } } diff --git a/tests/integration/Validation/Validator/Identical/ConstructCest.php b/tests/integration/Validation/Validator/Identical/ConstructCest.php index 9ec405d4b69..29e6bc08e02 100644 --- a/tests/integration/Validation/Validator/Identical/ConstructCest.php +++ b/tests/integration/Validation/Validator/Identical/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorIdenticalConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Identical - __construct()'); + $validator = new Identical(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Identical/GetOptionCest.php b/tests/integration/Validation/Validator/Identical/GetOptionCest.php index ad3b9dad5dd..f969c94a1ed 100644 --- a/tests/integration/Validation/Validator/Identical/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Identical/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorIdenticalGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Identical - getOption()'); + $validator = new Identical(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Identical/HasOptionCest.php b/tests/integration/Validation/Validator/Identical/HasOptionCest.php index 79362a8cb05..ac1a4e5e70e 100644 --- a/tests/integration/Validation/Validator/Identical/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Identical/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorIdenticalHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Identical - hasOption()'); - $validator = new Identical(['message' => 'This is a message']); + + $validator = new Identical( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Identical/SetOptionCest.php b/tests/integration/Validation/Validator/Identical/SetOptionCest.php index eefcb43199d..c83d1b70ff2 100644 --- a/tests/integration/Validation/Validator/Identical/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Identical/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorIdenticalSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Identical - setOption()'); + $validator = new Identical(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Identical/ValidateCest.php b/tests/integration/Validation/Validator/Identical/ValidateCest.php index 1842e9d6423..4de279fa0e8 100644 --- a/tests/integration/Validation/Validator/Identical/ValidateCest.php +++ b/tests/integration/Validation/Validator/Identical/ValidateCest.php @@ -30,6 +30,7 @@ class ValidateCest public function validationValidatorIdenticalValidate(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Identical - validate()'); + $I->skipTest('Need implementation'); } } diff --git a/tests/integration/Validation/Validator/InclusionIn/ConstructCest.php b/tests/integration/Validation/Validator/InclusionIn/ConstructCest.php index a00f7f491e7..28bd7d48092 100644 --- a/tests/integration/Validation/Validator/InclusionIn/ConstructCest.php +++ b/tests/integration/Validation/Validator/InclusionIn/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorInclusionInConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\InclusionIn - __construct()'); + $validator = new InclusionIn(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/InclusionIn/GetOptionCest.php b/tests/integration/Validation/Validator/InclusionIn/GetOptionCest.php index 30817406e49..329ce7062c0 100644 --- a/tests/integration/Validation/Validator/InclusionIn/GetOptionCest.php +++ b/tests/integration/Validation/Validator/InclusionIn/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorInclusionInGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\InclusionIn - getOption()'); + $validator = new InclusionIn(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/InclusionIn/HasOptionCest.php b/tests/integration/Validation/Validator/InclusionIn/HasOptionCest.php index b0cea3e2224..2f7cf1704ef 100644 --- a/tests/integration/Validation/Validator/InclusionIn/HasOptionCest.php +++ b/tests/integration/Validation/Validator/InclusionIn/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorInclusionInHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\InclusionIn - hasOption()'); - $validator = new InclusionIn(['message' => 'This is a message']); + + $validator = new InclusionIn( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/InclusionIn/SetOptionCest.php b/tests/integration/Validation/Validator/InclusionIn/SetOptionCest.php index b6abef5f452..76b42966fab 100644 --- a/tests/integration/Validation/Validator/InclusionIn/SetOptionCest.php +++ b/tests/integration/Validation/Validator/InclusionIn/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorInclusionInSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\InclusionIn - setOption()'); + $validator = new InclusionIn(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/InclusionIn/ValidateCest.php b/tests/integration/Validation/Validator/InclusionIn/ValidateCest.php index 0bf94bc3a2b..9945fbd692d 100644 --- a/tests/integration/Validation/Validator/InclusionIn/ValidateCest.php +++ b/tests/integration/Validation/Validator/InclusionIn/ValidateCest.php @@ -30,6 +30,7 @@ class ValidateCest public function validationValidatorInclusioninValidate(IntegrationTester $I) { $I->wantToTest('Validation\Validator\InclusionIn - validate()'); + $I->skipTest('Need implementation'); } } diff --git a/tests/integration/Validation/Validator/Ip/ConstructCest.php b/tests/integration/Validation/Validator/Ip/ConstructCest.php index a4a94042cc3..8f64d151c68 100644 --- a/tests/integration/Validation/Validator/Ip/ConstructCest.php +++ b/tests/integration/Validation/Validator/Ip/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorIpConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Ip - __construct()'); + $validator = new Ip(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Ip/GetOptionCest.php b/tests/integration/Validation/Validator/Ip/GetOptionCest.php index 4eefb833bee..cdbcb284216 100644 --- a/tests/integration/Validation/Validator/Ip/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Ip/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorIpGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Ip - getOption()'); + $validator = new Ip(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Ip/HasOptionCest.php b/tests/integration/Validation/Validator/Ip/HasOptionCest.php index 30f17e6aa5e..c6f261885b9 100644 --- a/tests/integration/Validation/Validator/Ip/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Ip/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorIpHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Ip - hasOption()'); - $validator = new Ip(['message' => 'This is a message']); + + $validator = new Ip( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Ip/SetOptionCest.php b/tests/integration/Validation/Validator/Ip/SetOptionCest.php index 983cf5953c3..5fae8c02c55 100644 --- a/tests/integration/Validation/Validator/Ip/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Ip/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorIpSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Ip - setOption()'); + $validator = new Ip(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Ip/ValidateCest.php b/tests/integration/Validation/Validator/Ip/ValidateCest.php index e5f0d32434a..cbbfb39c414 100644 --- a/tests/integration/Validation/Validator/Ip/ValidateCest.php +++ b/tests/integration/Validation/Validator/Ip/ValidateCest.php @@ -32,7 +32,9 @@ class ValidateCest public function validationValidatorIpSingleField(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Ip :: validate() - single field'); + $validation = new Validation(); + $validation->add( 'ip', new Ip( @@ -46,27 +48,49 @@ public function validationValidatorIpSingleField(IntegrationTester $I) ) ); - $actual = $validation->validate(['ip' => '127.0.0.1']); - $I->assertEmpty($actual); + $I->assertEmpty( + $validation->validate( + [ + 'ip' => '127.0.0.1', + ] + ) + ); + + $I->assertEmpty( + $validation->validate( + [ + 'ip' => '', + ] + ) + ); + + $I->assertEmpty( + $validation->validate( + [ + 'ip' => '', + ] + ) + ); - $actual = $validation->validate(['ip' => '']); - $I->assertEmpty($actual); - $actual = $validation->validate(['ip' => '']); - $I->assertEmpty($actual); $messages = $validation->validate( [ 'ip' => '2001:cdba:0000:0000:0000:0000:3257:9652', ] ); + $I->assertNotEmpty($messages); - $expected = 'This is a test message'; - $actual = (string) $messages[0]; - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'This is a test message', + (string) $messages[0] + ); + + $validation = new Validation(); + $validation->add( 'ip', new Ip( @@ -80,21 +104,37 @@ public function validationValidatorIpSingleField(IntegrationTester $I) ) ); - $actual = $validation->validate(['ip' => '127.0.0.1']); - $I->assertNotEmpty($actual); + $I->assertNotEmpty( + $validation->validate( + [ + 'ip' => '127.0.0.1', + ] + ) + ); - $actual = $validation->validate(['ip' => '']); - $I->assertNotEmpty($actual); + $I->assertNotEmpty( + $validation->validate( + [ + 'ip' => '', + ] + ) + ); - $actual = $validation->validate(['ip' => '']); - $I->assertNotEmpty($actual); + $I->assertNotEmpty( + $validation->validate( + [ + 'ip' => '', + ] + ) + ); - $messages = $validation->validate( - [ - 'ip' => '2001:cdba:0000:0000:0000:0000:3257:9652', - ] + $I->assertEmpty( + $validation->validate( + [ + 'ip' => '2001:cdba:0000:0000:0000:0000:3257:9652', + ] + ) ); - $I->assertEmpty($messages); } /** @@ -108,7 +148,9 @@ public function validationValidatorIpSingleField(IntegrationTester $I) public function validationValidatorIpMultipleField(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Ip :: validate() - multiple field'); + $validation = new Validation(); + $validation->add( [ 'ip', @@ -140,36 +182,48 @@ public function validationValidatorIpMultipleField(IntegrationTester $I) ) ); + + $messages = $validation->validate( [ 'ip' => '127.0.0.1', 'anotherIp' => '127.0.0.1', ] ); + $I->assertCount(1, $messages); + + $messages = $validation->validate( [ 'ip' => '192.168.10.20', 'anotherIp' => '192.168.10.20', ] ); + $I->assertCount(1, $messages); + + $messages = $validation->validate( [ 'ip' => '192.168.10.20', 'anotherIp' => '', ] ); + $I->assertCount(0, $messages); + + $messages = $validation->validate( [ 'ip' => '2001:cdba:0000:0000:0000:0000:3257:9652', 'anotherIp' => '2001:cdba:0000:0000:0000:0000:3257:9652', ] ); + $I->assertCount(1, $messages); } } diff --git a/tests/integration/Validation/Validator/Numericality/ConstructCest.php b/tests/integration/Validation/Validator/Numericality/ConstructCest.php index 6b9d97726e7..dd1707f8633 100644 --- a/tests/integration/Validation/Validator/Numericality/ConstructCest.php +++ b/tests/integration/Validation/Validator/Numericality/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorNumericalityConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Numericality - __construct()'); + $validator = new Numericality(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Numericality/GetOptionCest.php b/tests/integration/Validation/Validator/Numericality/GetOptionCest.php index f93b4a3dac3..3e41e69cd94 100644 --- a/tests/integration/Validation/Validator/Numericality/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Numericality/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorNumericalityGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Numericality - getOption()'); + $validator = new Numericality(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Numericality/HasOptionCest.php b/tests/integration/Validation/Validator/Numericality/HasOptionCest.php index 04892170960..fd25bc4400e 100644 --- a/tests/integration/Validation/Validator/Numericality/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Numericality/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorNumericalityHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Numericality - hasOption()'); - $validator = new Numericality(['message' => 'This is a message']); + + $validator = new Numericality( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Numericality/SetOptionCest.php b/tests/integration/Validation/Validator/Numericality/SetOptionCest.php index 73d9362b4d8..cab1820e5f7 100644 --- a/tests/integration/Validation/Validator/Numericality/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Numericality/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorNumericalitySetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Numericality - setOption()'); + $validator = new Numericality(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Numericality/ValidateCest.php b/tests/integration/Validation/Validator/Numericality/ValidateCest.php index bf3441db5fb..e34aeb30699 100644 --- a/tests/integration/Validation/Validator/Numericality/ValidateCest.php +++ b/tests/integration/Validation/Validator/Numericality/ValidateCest.php @@ -30,6 +30,7 @@ class ValidateCest public function validationValidatorNumericalityValidate(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Numericality - validate()'); + $I->skipTest('Need implementation'); } } diff --git a/tests/integration/Validation/Validator/NumericalityCest.php b/tests/integration/Validation/Validator/NumericalityCest.php index 29f3e964190..67615ac11af 100644 --- a/tests/integration/Validation/Validator/NumericalityCest.php +++ b/tests/integration/Validation/Validator/NumericalityCest.php @@ -57,11 +57,13 @@ public function validationValidatorSingleField(IntegrationTester $I) */ public function validationValidatorMultipleField(IntegrationTester $I) { - $validation = new Validation(); + $validation = new Validation(); + $validationMessages = [ 'amount' => 'Amount must be digit.', 'price' => 'Price must be digit.', ]; + $validation->add( [ 'amount', @@ -73,24 +75,46 @@ public function validationValidatorMultipleField(IntegrationTester $I) ] ) ); - $messages = $validation->validate(['amount' => 123, 'price' => 123]); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['amount' => '123abc', 'price' => 123]); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'amount' => 123, + 'price' => 123, + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + + $messages = $validation->validate( + [ + 'amount' => '123abc', + 'price' => 123, + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); $expected = $validationMessages['amount']; $actual = $messages->offsetGet(0)->getMessage(); $I->assertEquals($expected, $actual); - $messages = $validation->validate(['amount' => '123abc', 'price' => '123abc']); - $expected = 2; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'amount' => '123abc', + 'price' => '123abc', + ] + ); + + $I->assertEquals( + 2, + $messages->count() + ); $expected = $validationMessages['amount']; $actual = $messages->offsetGet(0)->getMessage(); @@ -112,33 +136,62 @@ public function validationValidatorMultipleField(IntegrationTester $I) public function validationValidatorLocales(IntegrationTester $I) { $validation = new Validation(); - $validation->add('amount', new Numericality()); + + $validation->add( + 'amount', + new Numericality() + ); // get default locale $locale = setlocale(LC_ALL, 0); + $this->setTestLocale('en_US.UTF8'); - $messages = $validation->validate(['amount' => 123.12]); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'amount' => 123.12, + ] + ); - $messages = $validation->validate(['amount' => '123.12']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 0, + $messages->count() + ); - $messages = $validation->validate(['amount' => '123,12']); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'amount' => '123.12', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + + $messages = $validation->validate( + [ + 'amount' => '123,12', + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); $this->setTestLocale('fr_FR.UTF8'); - $messages = $validation->validate(['amount' => 123.12]); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'amount' => 123.12, + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); // revert back locale $this->setTestLocale($locale); @@ -159,6 +212,7 @@ protected function setTestLocale($locale) putenv('LC_ALL=' . $locale); putenv('LANG=' . $locale); putenv('LANGUAGE=' . $locale); + return setlocale(LC_ALL, $locale); } } diff --git a/tests/integration/Validation/Validator/PresenceOf/ConstructCest.php b/tests/integration/Validation/Validator/PresenceOf/ConstructCest.php index 56950b2fb0c..3019a05ab96 100644 --- a/tests/integration/Validation/Validator/PresenceOf/ConstructCest.php +++ b/tests/integration/Validation/Validator/PresenceOf/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorPresenceOfConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\PresenceOf - __construct()'); + $validator = new PresenceOf(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/PresenceOf/GetOptionCest.php b/tests/integration/Validation/Validator/PresenceOf/GetOptionCest.php index 1bad561f1d3..b82c687b4f5 100644 --- a/tests/integration/Validation/Validator/PresenceOf/GetOptionCest.php +++ b/tests/integration/Validation/Validator/PresenceOf/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorPresenceOfGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\PresenceOf - getOption()'); + $validator = new PresenceOf(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/PresenceOf/HasOptionCest.php b/tests/integration/Validation/Validator/PresenceOf/HasOptionCest.php index e3b41d4ff9d..b81d2999f46 100644 --- a/tests/integration/Validation/Validator/PresenceOf/HasOptionCest.php +++ b/tests/integration/Validation/Validator/PresenceOf/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorPresenceOfHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\PresenceOf - hasOption()'); - $validator = new PresenceOf(['message' => 'This is a message']); + + $validator = new PresenceOf( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/PresenceOf/SetOptionCest.php b/tests/integration/Validation/Validator/PresenceOf/SetOptionCest.php index 0c27a4114b8..c38d38a8fd4 100644 --- a/tests/integration/Validation/Validator/PresenceOf/SetOptionCest.php +++ b/tests/integration/Validation/Validator/PresenceOf/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorPresenceOfSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\PresenceOf - setOption()'); + $validator = new PresenceOf(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/PresenceOf/ValidateCest.php b/tests/integration/Validation/Validator/PresenceOf/ValidateCest.php index 2e02df58f98..47e2c352db6 100644 --- a/tests/integration/Validation/Validator/PresenceOf/ValidateCest.php +++ b/tests/integration/Validation/Validator/PresenceOf/ValidateCest.php @@ -30,6 +30,7 @@ class ValidateCest public function validationValidatorPresenceofValidate(IntegrationTester $I) { $I->wantToTest('Validation\Validator\PresenceOf - validate()'); + $I->skipTest('Need implementation'); } } diff --git a/tests/integration/Validation/Validator/Regex/ConstructCest.php b/tests/integration/Validation/Validator/Regex/ConstructCest.php index dac5d85815f..e1225a6af8a 100644 --- a/tests/integration/Validation/Validator/Regex/ConstructCest.php +++ b/tests/integration/Validation/Validator/Regex/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorRegexConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Regex - __construct()'); + $validator = new Regex(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Regex/GetOptionCest.php b/tests/integration/Validation/Validator/Regex/GetOptionCest.php index d446867be5f..02686d9efa9 100644 --- a/tests/integration/Validation/Validator/Regex/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Regex/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorRegexGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Regex - getOption()'); + $validator = new Regex(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Regex/HasOptionCest.php b/tests/integration/Validation/Validator/Regex/HasOptionCest.php index 14ae08bd8f4..f13ef0c9bc0 100644 --- a/tests/integration/Validation/Validator/Regex/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Regex/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorRegexHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Regex - hasOption()'); - $validator = new Regex(['message' => 'This is a message']); + + $validator = new Regex( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Regex/SetOptionCest.php b/tests/integration/Validation/Validator/Regex/SetOptionCest.php index f2dd4780b4a..62abe28115d 100644 --- a/tests/integration/Validation/Validator/Regex/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Regex/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorRegexSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Regex - setOption()'); + $validator = new Regex(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Regex/ValidateCest.php b/tests/integration/Validation/Validator/Regex/ValidateCest.php index c813db1f933..ef728960bbd 100644 --- a/tests/integration/Validation/Validator/Regex/ValidateCest.php +++ b/tests/integration/Validation/Validator/Regex/ValidateCest.php @@ -30,6 +30,7 @@ class ValidateCest public function validationValidatorRegexValidate(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Regex - validate()'); + $I->skipTest('Need implementation'); } } diff --git a/tests/integration/Validation/Validator/RegexCest.php b/tests/integration/Validation/Validator/RegexCest.php index d949b0d9bd9..28cb2e25c1f 100644 --- a/tests/integration/Validation/Validator/RegexCest.php +++ b/tests/integration/Validation/Validator/RegexCest.php @@ -38,7 +38,10 @@ public function validationValidatorSingleField(IntegrationTester $I) ) ); - $messages = $validation->validate([]); + $messages = $validation->validate( + [] + ); + $expected = new Messages( [ new Message( @@ -49,13 +52,19 @@ public function validationValidatorSingleField(IntegrationTester $I) ), ] ); - $actual = $messages; - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['car_plate' => 'XYZ-123']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals($expected, $messages); + + $messages = $validation->validate( + [ + 'car_plate' => 'XYZ-123', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); } /** @@ -66,11 +75,13 @@ public function validationValidatorSingleField(IntegrationTester $I) */ public function validationValidatorMultipleFieldSinglePattern(IntegrationTester $I) { - $validation = new Validation(); + $validation = new Validation(); + $validationMessages = [ 'name' => 'Name can be only lowercase letters.', 'type' => 'Type can be only lowercase letters.', ]; + $validation->add( [ 'name', @@ -83,24 +94,47 @@ public function validationValidatorMultipleFieldSinglePattern(IntegrationTester ] ) ); - $messages = $validation->validate(['name' => 'somevalue', 'type' => 'somevalue']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['name' => 'SomeValue', 'type' => 'somevalue']); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'name' => 'somevalue', + 'type' => 'somevalue', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + + $messages = $validation->validate( + [ + 'name' => 'SomeValue', + 'type' => 'somevalue', + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); $expected = $validationMessages['name']; $actual = $messages->offsetGet(0)->getMessage(); $I->assertEquals($expected, $actual); - $messages = $validation->validate(['name' => 'SomeValue', 'type' => 'SomeValue']); - $expected = 2; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'name' => 'SomeValue', + 'type' => 'SomeValue', + ] + ); + + + $I->assertEquals( + 2, + $messages->count() + ); $expected = $validationMessages['name']; $actual = $messages->offsetGet(0)->getMessage(); @@ -119,11 +153,13 @@ public function validationValidatorMultipleFieldSinglePattern(IntegrationTester */ public function validationValidatorMultipleFieldMultiplePattern(IntegrationTester $I) { - $validation = new Validation(); + $validation = new Validation(); + $validationMessages = [ 'name' => 'Name can be only lowercase letters.', 'type' => 'Type can be only uppercase letters.', ]; + $validation->add( [ 'name', @@ -139,33 +175,62 @@ public function validationValidatorMultipleFieldMultiplePattern(IntegrationTeste ] ) ); - $messages = $validation->validate(['name' => 'somevalue', 'type' => 'SOMEVALUE']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['name' => 'SomeValue', 'type' => 'SOMEVALUE']); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'name' => 'somevalue', + 'type' => 'SOMEVALUE', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + + $messages = $validation->validate( + [ + 'name' => 'SomeValue', + 'type' => 'SOMEVALUE', + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); $expected = $validationMessages['name']; $actual = $messages->offsetGet(0)->getMessage(); $I->assertEquals($expected, $actual); - $messages = $validation->validate(['name' => 'somevalue', 'type' => 'somevalue']); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'name' => 'somevalue', + 'type' => 'somevalue', + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); $expected = $validationMessages['type']; $actual = $messages->offsetGet(0)->getMessage(); $I->assertEquals($expected, $actual); - $messages = $validation->validate(['name' => 'SomeValue', 'type' => 'SomeValue']); - $expected = 2; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'name' => 'SomeValue', + 'type' => 'SomeValue', + ] + ); + + $I->assertEquals( + 2, + $messages->count() + ); $expected = $validationMessages['name']; $actual = $messages->offsetGet(0)->getMessage(); @@ -190,7 +255,10 @@ public function validationValidatorCustomMessage(IntegrationTester $I) ) ); - $messages = $validation->validate([]); + $messages = $validation->validate( + [] + ); + $expected = new Messages( [ new Message( @@ -201,12 +269,18 @@ public function validationValidatorCustomMessage(IntegrationTester $I) ), ] ); - $actual = $messages; - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['car_plate' => 'XYZ-123']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals($expected, $messages); + + $messages = $validation->validate( + [ + 'car_plate' => 'XYZ-123', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); } } diff --git a/tests/integration/Validation/Validator/StringLength/ConstructCest.php b/tests/integration/Validation/Validator/StringLength/ConstructCest.php index b9753c66854..0447df5b2d7 100644 --- a/tests/integration/Validation/Validator/StringLength/ConstructCest.php +++ b/tests/integration/Validation/Validator/StringLength/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorStringLengthConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\StringLength - __construct()'); + $validator = new StringLength(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/StringLength/GetOptionCest.php b/tests/integration/Validation/Validator/StringLength/GetOptionCest.php index 7304ba3e535..91ec53695bc 100644 --- a/tests/integration/Validation/Validator/StringLength/GetOptionCest.php +++ b/tests/integration/Validation/Validator/StringLength/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorStringLengthGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\StringLength - getOption()'); + $validator = new StringLength(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/StringLength/HasOptionCest.php b/tests/integration/Validation/Validator/StringLength/HasOptionCest.php index e262e070802..75a8f9c5462 100644 --- a/tests/integration/Validation/Validator/StringLength/HasOptionCest.php +++ b/tests/integration/Validation/Validator/StringLength/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorStringLengthHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\StringLength - hasOption()'); - $validator = new StringLength(['message' => 'This is a message']); + + $validator = new StringLength( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/StringLength/SetOptionCest.php b/tests/integration/Validation/Validator/StringLength/SetOptionCest.php index 071bbac28e3..8f6d9aac3ac 100644 --- a/tests/integration/Validation/Validator/StringLength/SetOptionCest.php +++ b/tests/integration/Validation/Validator/StringLength/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorStringLengthSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\StringLength - setOption()'); + $validator = new StringLength(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/StringLength/ValidateCest.php b/tests/integration/Validation/Validator/StringLength/ValidateCest.php index 75980ff57d4..6b14e4864e2 100644 --- a/tests/integration/Validation/Validator/StringLength/ValidateCest.php +++ b/tests/integration/Validation/Validator/StringLength/ValidateCest.php @@ -35,7 +35,9 @@ class ValidateCest public function validationValidatorStringLengthValidateSingleField(IntegrationTester $I) { $I->wantToTest('Validation\Validator\StringLength :: validate() - single field'); + $validation = new Validation(); + $validation->add( 'name', new StringLength( @@ -46,15 +48,32 @@ public function validationValidatorStringLengthValidateSingleField(IntegrationTe ) ); - $messages = $validation->validate(['name' => 'SomeValue']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['name' => 'SomeValue123']); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + + $messages = $validation->validate( + [ + 'name' => 'SomeValue', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + + + + $messages = $validation->validate( + [ + 'name' => 'SomeValue123', + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); } /** @@ -68,13 +87,32 @@ public function validationValidatorStringLengthValidateSingleField(IntegrationTe public function validationValidatorStringLengthValidateMinimum(IntegrationTester $I) { $I->wantToTest('Validation\Validator\StringLength :: validate() - minimum'); + $validation = new Validation(); - $validation->add('name', new StringLength(['min' => 3])); - $messages = $validation->validate(['name' => 'Something']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $validation->add( + 'name', + new StringLength( + [ + 'min' => 3, + ] + ) + ); + + + + $messages = $validation->validate( + [ + 'name' => 'Something', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + + $expected = new Messages( [ @@ -86,9 +124,14 @@ public function validationValidatorStringLengthValidateMinimum(IntegrationTester ), ] ); - $messages = $validation->validate(['name' => 'So']); - $actual = $messages; - $I->assertEquals($expected, $actual); + + $messages = $validation->validate( + [ + 'name' => 'So', + ] + ); + + $I->assertEquals($expected, $messages); } /** @@ -102,17 +145,36 @@ public function validationValidatorStringLengthValidateMinimum(IntegrationTester */ public function validationValidatorStringLengthValidateMinimumWithCustomMessage(IntegrationTester $I) { - $I->wantToTest('Validation\Validator\StringLength :: validate() - minimum custom message'); + $I->wantToTest( + 'Validation\Validator\StringLength :: validate() - minimum custom message' + ); + $validation = new Validation(); + $validation->add( 'message', - new StringLength(['min' => 3, 'messageMinimum' => 'The message is too short']) + new StringLength( + [ + 'min' => 3, + 'messageMinimum' => 'The message is too short', + ] + ) + ); + + + + $messages = $validation->validate( + [ + 'message' => 'Something', + ] + ); + + $I->assertEquals( + 0, + $messages->count() ); - $messages = $validation->validate(['message' => 'Something']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $expected = new Messages( [ @@ -124,9 +186,14 @@ public function validationValidatorStringLengthValidateMinimumWithCustomMessage( ), ] ); - $messages = $validation->validate(['message' => 'So']); - $actual = $messages; - $I->assertEquals($expected, $actual); + + $messages = $validation->validate( + [ + 'message' => 'So', + ] + ); + + $I->assertEquals($expected, $messages); } /** @@ -140,13 +207,32 @@ public function validationValidatorStringLengthValidateMinimumWithCustomMessage( public function validationValidatorStringLengthValidateMaximum(IntegrationTester $I) { $I->wantToTest('Validation\Validator\StringLength :: validate() - maximum'); + $validation = new Validation(); - $validation->add('name', new StringLength(['max' => 4])); - $messages = $validation->validate(['name' => 'John']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $validation->add( + 'name', + new StringLength( + [ + 'max' => 4, + ] + ) + ); + + + + $messages = $validation->validate( + [ + 'name' => 'John', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + + $expected = new Messages( [ @@ -158,9 +244,14 @@ public function validationValidatorStringLengthValidateMaximum(IntegrationTester ), ] ); - $messages = $validation->validate(['name' => 'Johannes']); - $actual = $messages; - $I->assertEquals($expected, $actual); + + $messages = $validation->validate( + [ + 'name' => 'Johannes', + ] + ); + + $I->assertEquals($expected, $messages); } /** @@ -174,17 +265,36 @@ public function validationValidatorStringLengthValidateMaximum(IntegrationTester */ public function validationValidatorStringLengthValidateMaximumWithCustomMessage(IntegrationTester $I) { - $I->wantToTest('Validation\Validator\StringLength :: validate() - maximum custom message'); + $I->wantToTest( + 'Validation\Validator\StringLength :: validate() - maximum custom message' + ); + $validation = new Validation(); + $validation->add( 'message', - new StringLength(['max' => 4, 'messageMaximum' => 'The message is too long']) + new StringLength( + [ + 'max' => 4, + 'messageMaximum' => 'The message is too long', + ] + ) + ); + + + + $messages = $validation->validate( + [ + 'message' => 'Pet', + ] ); - $messages = $validation->validate(['message' => 'Pet']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 0, + $messages->count() + ); + + $expected = new Messages( [ @@ -196,9 +306,14 @@ public function validationValidatorStringLengthValidateMaximumWithCustomMessage( ), ] ); - $messages = $validation->validate(['message' => 'Validation']); - $actual = $messages; - $I->assertEquals($expected, $actual); + + $messages = $validation->validate( + [ + 'message' => 'Validation', + ] + ); + + $I->assertEquals($expected, $messages); } /** @@ -212,16 +327,22 @@ public function validationValidatorStringLengthValidateMaximumWithCustomMessage( */ public function validationValidatorStringLengthValidateMultipleFieldSingleMinMax(IntegrationTester $I) { - $I->wantToTest('Validation\Validator\StringLength :: validate() - multiple field and single min, max'); - $validation = new Validation(); + $I->wantToTest( + 'Validation\Validator\StringLength :: validate() - multiple field and single min, max' + ); + + $validation = new Validation(); + $validationMinimumMessages = [ 'name' => 'Name length must be minimum 0.', 'type' => 'Type length must be minimum 0.', ]; + $validationMaximumMessages = [ 'name' => 'Name length must be maximum 9.', 'type' => 'Type length must be maximum 9.', ]; + $validation->add( [ 'name', @@ -237,32 +358,62 @@ public function validationValidatorStringLengthValidateMultipleFieldSingleMinMax ) ); - $messages = $validation->validate(['name' => 'SomeValue', 'type' => 'SomeValue']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['name' => 'SomeValue123', 'type' => 'SomeValue']); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $expected = $validationMaximumMessages['name']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'name' => 'SomeValue', + 'type' => 'SomeValue', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); + + + + $messages = $validation->validate( + [ + 'name' => 'SomeValue123', + 'type' => 'SomeValue', + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); + + $I->assertEquals( + $validationMaximumMessages['name'], + $messages->offsetGet(0)->getMessage() + ); + + + + $messages = $validation->validate( + [ + 'name' => 'SomeValue123', + 'type' => 'SomeValue123', + ] + ); - $messages = $validation->validate(['name' => 'SomeValue123', 'type' => 'SomeValue123']); - $expected = 2; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 2, + $messages->count() + ); - $expected = $validationMaximumMessages['name']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $validationMaximumMessages['name'], + $messages->offsetGet(0)->getMessage() + ); - $expected = $validationMaximumMessages['type']; - $actual = $messages->offsetGet(1)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $validationMaximumMessages['type'], + $messages->offsetGet(1)->getMessage() + ); } /** @@ -277,15 +428,19 @@ public function validationValidatorStringLengthValidateMultipleFieldSingleMinMax public function validationValidatorStringLengthValidateMultipleFieldMultipleMinMax(IntegrationTester $I) { $I->wantToTest('Validation\Validator\StringLength :: validate() - multiple field and min, max'); - $validation = new Validation(); + + $validation = new Validation(); + $validationMinimumMessages = [ 'name' => 'Name length must be minimum 0.', 'type' => 'Type length must be minimum 0.', ]; + $validationMaximumMessages = [ 'name' => 'Name length must be maximum 9.', 'type' => 'Type length must be maximum 4.', ]; + $validation->add( [ 'name', @@ -307,40 +462,80 @@ public function validationValidatorStringLengthValidateMultipleFieldMultipleMinM ) ); - $messages = $validation->validate(['name' => 'SomeValue', 'type' => 'Some']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['name' => 'SomeValue123', 'type' => 'Some']); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $expected = $validationMaximumMessages['name']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'name' => 'SomeValue', + 'type' => 'Some', + ] + ); - $messages = $validation->validate(['name' => 'SomeValue', 'type' => 'SomeValue']); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 0, + $messages->count() + ); - $expected = $validationMaximumMessages['type']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['name' => 'SomeValue123', 'type' => 'SomeValue']); - $expected = 2; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $expected = $validationMaximumMessages['name']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); + $messages = $validation->validate( + [ + 'name' => 'SomeValue123', + 'type' => 'Some', + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); + + $I->assertEquals( + $validationMaximumMessages['name'], + $messages->offsetGet(0)->getMessage() + ); - $expected = $validationMaximumMessages['type']; - $actual = $messages->offsetGet(1)->getMessage(); - $I->assertEquals($expected, $actual); + + + $messages = $validation->validate( + [ + 'name' => 'SomeValue', + 'type' => 'SomeValue', + ] + ); + + $I->assertEquals( + 1, + $messages->count() + ); + + $I->assertEquals( + $validationMaximumMessages['type'], + $messages->offsetGet(0)->getMessage() + ); + + + + $messages = $validation->validate( + [ + 'name' => 'SomeValue123', + 'type' => 'SomeValue', + ] + ); + + $I->assertEquals( + 2, + $messages->count() + ); + + $I->assertEquals( + $validationMaximumMessages['name'], + $messages->offsetGet(0)->getMessage() + ); + + $I->assertEquals( + $validationMaximumMessages['type'], + $messages->offsetGet(1)->getMessage() + ); } } diff --git a/tests/integration/Validation/Validator/Uniqueness/ConstructCest.php b/tests/integration/Validation/Validator/Uniqueness/ConstructCest.php index 74fc9f7cd3c..13af773c26d 100644 --- a/tests/integration/Validation/Validator/Uniqueness/ConstructCest.php +++ b/tests/integration/Validation/Validator/Uniqueness/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorUniquenessConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Uniqueness - __construct()'); + $validator = new Uniqueness(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Uniqueness/GetOptionCest.php b/tests/integration/Validation/Validator/Uniqueness/GetOptionCest.php index 63c6b08f668..43297116c9b 100644 --- a/tests/integration/Validation/Validator/Uniqueness/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Uniqueness/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorUniquenessGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Uniqueness - getOption()'); + $validator = new Uniqueness(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Uniqueness/HasOptionCest.php b/tests/integration/Validation/Validator/Uniqueness/HasOptionCest.php index 21670c295d6..6026ebb92f9 100644 --- a/tests/integration/Validation/Validator/Uniqueness/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Uniqueness/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorUniquenessHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Uniqueness - hasOption()'); - $validator = new Uniqueness(['message' => 'This is a message']); + + $validator = new Uniqueness( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Uniqueness/SetOptionCest.php b/tests/integration/Validation/Validator/Uniqueness/SetOptionCest.php index 21152e8b863..a7bf98a8cbd 100644 --- a/tests/integration/Validation/Validator/Uniqueness/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Uniqueness/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorUniquenessSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Uniqueness - setOption()'); + $validator = new Uniqueness(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Uniqueness/ValidateCest.php b/tests/integration/Validation/Validator/Uniqueness/ValidateCest.php index b8c3b7e7716..9c19463bf32 100644 --- a/tests/integration/Validation/Validator/Uniqueness/ValidateCest.php +++ b/tests/integration/Validation/Validator/Uniqueness/ValidateCest.php @@ -30,6 +30,7 @@ class ValidateCest public function validationValidatorUniquenessValidate(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Uniqueness - validate()'); + $I->skipTest('Need implementation'); } } diff --git a/tests/integration/Validation/Validator/UniquenessCest.php b/tests/integration/Validation/Validator/UniquenessCest.php index 25ef13f60e6..ce4e6bc0ded 100644 --- a/tests/integration/Validation/Validator/UniquenessCest.php +++ b/tests/integration/Validation/Validator/UniquenessCest.php @@ -47,7 +47,8 @@ public function _before(IntegrationTester $I) { $this->setNewFactoryDefault(); $this->setDiMysql(); - $this->robot = new Robots( + + $this->robot = new Robots( [ 'name' => 'Robotina', 'type' => 'mechanical', @@ -57,6 +58,7 @@ public function _before(IntegrationTester $I) 'text' => 'text', ] ); + $this->anotherRobot = new Robots( [ 'name' => 'Robotina', @@ -67,6 +69,7 @@ public function _before(IntegrationTester $I) 'text' => 'text', ] ); + $this->deletedRobot = new Robots( [ 'name' => 'Robotina', @@ -88,17 +91,25 @@ public function _before(IntegrationTester $I) public function testSingleField(IntegrationTester $I) { $validation = new Validation(); - $validation->add('type', new Uniqueness()); + + $validation->add( + 'type', + new Uniqueness() + ); + $messages = $validation->validate(null, $this->robot); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + $messages->count() + ); $messages = $validation->validate(null, $this->anotherRobot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); } /** @@ -110,16 +121,26 @@ public function testSingleField(IntegrationTester $I) public function testSingleFieldConvert(IntegrationTester $I) { $validation = new Validation(); - $validation->add('type', new Uniqueness([ - 'convert' => function (array $values) { - $values['type'] = 'hydraulic'; // mechanical -> hydraulic - return $values; - }, - ])); + + $validation->add( + 'type', + new Uniqueness( + [ + 'convert' => function (array $values) { + $values['type'] = 'hydraulic'; // mechanical -> hydraulic + + return $values; + }, + ] + ) + ); + $messages = $validation->validate(null, $this->robot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); } /** @@ -131,21 +152,32 @@ public function testSingleFieldConvert(IntegrationTester $I) public function testSingleFieldWithNull(IntegrationTester $I) { $validation = new Validation(); - $validation->add('deleted', new Uniqueness()); + + $validation->add( + 'deleted', + new Uniqueness() + ); + $messages = $validation->validate(null, $this->robot); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 1, + $messages->count() + ); $messages = $validation->validate(null, $this->anotherRobot); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 1, + $messages->count() + ); $messages = $validation->validate(null, $this->deletedRobot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); } /** @@ -157,16 +189,25 @@ public function testSingleFieldWithNull(IntegrationTester $I) public function testMultipleFields(IntegrationTester $I) { $validation = new Validation(); - $validation->add(['name', 'type'], new Uniqueness()); + + $validation->add( + ['name', 'type'], + new Uniqueness() + ); + $messages = $validation->validate(null, $this->robot); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 1, + $messages->count() + ); $messages = $validation->validate(null, $this->anotherRobot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); } /** @@ -178,16 +219,26 @@ public function testMultipleFields(IntegrationTester $I) public function testMultipleFieldsConvert(IntegrationTester $I) { $validation = new Validation(); - $validation->add(['name', 'type'], new Uniqueness([ - 'convert' => function (array $values) { - $values['type'] = 'hydraulic'; // mechanical -> hydraulic - return $values; - }, - ])); + + $validation->add( + ['name', 'type'], + new Uniqueness( + [ + 'convert' => function (array $values) { + $values['type'] = 'hydraulic'; // mechanical -> hydraulic + + return $values; + }, + ] + ) + ); + $messages = $validation->validate(null, $this->robot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); } /** @@ -199,21 +250,32 @@ public function testMultipleFieldsConvert(IntegrationTester $I) public function testMultipleFieldsWithNull(IntegrationTester $I) { $validation = new Validation(); - $validation->add(['type', 'deleted'], new Uniqueness()); + + $validation->add( + ['type', 'deleted'], + new Uniqueness() + ); + $messages = $validation->validate(null, $this->robot); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 1, + $messages->count() + ); $messages = $validation->validate(null, $this->anotherRobot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); $messages = $validation->validate(null, $this->deletedRobot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); } /** @@ -225,18 +287,29 @@ public function testMultipleFieldsWithNull(IntegrationTester $I) public function testExceptSingleFieldSingleExcept(IntegrationTester $I) { $validation = new Validation(); - $validation->add('year', new Uniqueness([ - 'except' => 1972, - ])); + + $validation->add( + 'year', + new Uniqueness( + [ + 'except' => 1972, + ] + ) + ); + $messages = $validation->validate(null, $this->robot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); $messages = $validation->validate(null, $this->anotherRobot); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 1, + $messages->count() + ); } /** @@ -248,18 +321,29 @@ public function testExceptSingleFieldSingleExcept(IntegrationTester $I) public function testExceptSingleFieldMultipleExcept(IntegrationTester $I) { $validation = new Validation(); - $validation->add('year', new Uniqueness([ - 'except' => [1972, 1952], - ])); + + $validation->add( + 'year', + new Uniqueness( + [ + 'except' => [1972, 1952], + ] + ) + ); + $messages = $validation->validate(null, $this->robot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); $messages = $validation->validate(null, $this->anotherRobot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); } /** @@ -271,21 +355,32 @@ public function testExceptSingleFieldMultipleExcept(IntegrationTester $I) public function testExceptMultipleFieldSingleExcept(IntegrationTester $I) { $validation = new Validation(); - $validation->add(['type', 'year'], new Uniqueness([ - 'except' => [ - 'type' => 'mechanical', - 'year' => 1972, - ], - ])); + + $validation->add( + ['type', 'year'], + new Uniqueness( + [ + 'except' => [ + 'type' => 'mechanical', + 'year' => 1972, + ], + ] + ) + ); + $messages = $validation->validate(null, $this->robot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); $messages = $validation->validate(null, $this->anotherRobot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); } /** @@ -297,21 +392,32 @@ public function testExceptMultipleFieldSingleExcept(IntegrationTester $I) public function testExceptMultipleFieldMultipleExcept(IntegrationTester $I) { $validation = new Validation(); - $validation->add(['year', 'type'], new Uniqueness([ - 'except' => [ - 'year' => [1952, 1972], - 'type' => ['hydraulic', 'mechanical'], - ], - ])); + + $validation->add( + ['year', 'type'], + new Uniqueness( + [ + 'except' => [ + 'year' => [1952, 1972], + 'type' => ['hydraulic', 'mechanical'], + ], + ] + ) + ); + $messages = $validation->validate(null, $this->robot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); $messages = $validation->validate(null, $this->anotherRobot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); } /** @@ -323,15 +429,25 @@ public function testExceptMultipleFieldMultipleExcept(IntegrationTester $I) public function testConvertArrayReturnsArray(IntegrationTester $I) { $I->skipTest('TODO: Check the verify'); + $validation = new Validation(); - $validation->add('type', new Uniqueness([ - 'convert' => function (array $values) { - ($values); - return null; - }, - ])); + + $validation->add( + 'type', + new Uniqueness( + [ + 'convert' => function (array $values) { + ($values); + + return null; + }, + ] + ) + ); + try { $validation->validate(null, $this->robot); + verify_that(false); } catch (\Exception $e) { verify_that(true); @@ -347,27 +463,42 @@ public function testConvertArrayReturnsArray(IntegrationTester $I) public function testExceptOtherThanField(IntegrationTester $I) { $validation = new Validation(); - $validation->add('text', new Uniqueness([ - 'except' => [ - 'type' => ['mechanical', 'cyborg'], - ], - ])); + + $validation->add( + 'text', + new Uniqueness( + [ + 'except' => [ + 'type' => ['mechanical', 'cyborg'], + ], + ] + ) + ); + $messages = $validation->validate(null, $this->robot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); $messages = $validation->validate(null, $this->anotherRobot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); $anotherRobot = clone $this->anotherRobot; + $this->anotherRobot->create(); + $messages = $validation->validate(null, $anotherRobot); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 1, + $messages->count() + ); $this->anotherRobot->delete(); } @@ -381,18 +512,30 @@ public function testExceptOtherThanField(IntegrationTester $I) public function testIssue13398(IntegrationTester $I) { $validation = new Validation(); - $validation->add('theName', new Uniqueness()); - $robot = Robotters::findFirst(1); + + $validation->add( + 'theName', + new Uniqueness() + ); + + $robot = Robotters::findFirst(1); + $robot->theName = 'Astro Boy'; - $messages = $validation->validate(null, $robot); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $messages = $validation->validate(null, $robot); + + $I->assertEquals( + 1, + $messages->count() + ); $robot->theName = 'Astro Boyy'; - $messages = $validation->validate(null, $robot); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $messages = $validation->validate(null, $robot); + + $I->assertEquals( + 0, + $messages->count() + ); } } diff --git a/tests/integration/Validation/Validator/Url/ConstructCest.php b/tests/integration/Validation/Validator/Url/ConstructCest.php index c82a6c2635c..edbe01eca83 100644 --- a/tests/integration/Validation/Validator/Url/ConstructCest.php +++ b/tests/integration/Validation/Validator/Url/ConstructCest.php @@ -34,7 +34,9 @@ class ConstructCest public function validationValidatorUrlConstruct(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Url - __construct()'); + $validator = new Url(); + $this->checkConstruct($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Url/GetOptionCest.php b/tests/integration/Validation/Validator/Url/GetOptionCest.php index 67ece6afbd1..2281aa782b0 100644 --- a/tests/integration/Validation/Validator/Url/GetOptionCest.php +++ b/tests/integration/Validation/Validator/Url/GetOptionCest.php @@ -34,7 +34,9 @@ class GetOptionCest public function validationValidatorUrlGetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Url - getOption()'); + $validator = new Url(); + $this->checkGetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Url/HasOptionCest.php b/tests/integration/Validation/Validator/Url/HasOptionCest.php index 45209983af5..79c565fe39b 100644 --- a/tests/integration/Validation/Validator/Url/HasOptionCest.php +++ b/tests/integration/Validation/Validator/Url/HasOptionCest.php @@ -34,7 +34,13 @@ class HasOptionCest public function validationValidatorUrlHasOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Url - hasOption()'); - $validator = new Url(['message' => 'This is a message']); + + $validator = new Url( + [ + 'message' => 'This is a message', + ] + ); + $this->checkHasOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Url/SetOptionCest.php b/tests/integration/Validation/Validator/Url/SetOptionCest.php index 2c0c5369493..1a206bc0a94 100644 --- a/tests/integration/Validation/Validator/Url/SetOptionCest.php +++ b/tests/integration/Validation/Validator/Url/SetOptionCest.php @@ -34,7 +34,9 @@ class SetOptionCest public function validationValidatorUrlSetOption(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Url - setOption()'); + $validator = new Url(); + $this->checkSetOption($I, $validator); } } diff --git a/tests/integration/Validation/Validator/Url/ValidateCest.php b/tests/integration/Validation/Validator/Url/ValidateCest.php index 57a7a346800..5573bf2742f 100644 --- a/tests/integration/Validation/Validator/Url/ValidateCest.php +++ b/tests/integration/Validation/Validator/Url/ValidateCest.php @@ -34,10 +34,20 @@ class ValidateCest public function validationValidatorUrlSingleField(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Url :: validate() - single field'); + $validation = new Validation(); - $validation->add('url', new Url()); - $messages = $validation->validate([]); + $validation->add( + 'url', + new Url() + ); + + + + $messages = $validation->validate( + [] + ); + $expected = new Messages( [ new Message( @@ -48,17 +58,31 @@ public function validationValidatorUrlSingleField(IntegrationTester $I) ), ] ); - $actual = $messages; - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['url' => 'x=1']); - $actual = $messages; - $I->assertEquals($expected, $actual); + $I->assertEquals($expected, $messages); + + + + $messages = $validation->validate( + [ + 'url' => 'x=1', + ] + ); + + $I->assertEquals($expected, $messages); + - $messages = $validation->validate(['url' => 'http://phalconphp.com']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $messages = $validation->validate( + [ + 'url' => 'http://phalconphp.com', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); } /** @@ -72,11 +96,14 @@ public function validationValidatorUrlSingleField(IntegrationTester $I) public function validationValidatorUrlMultipleField(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Url :: validate() - multiple field'); - $validation = new Validation(); + + $validation = new Validation(); + $validationMessages = [ 'url' => 'Url must be correct url.', 'anotherUrl' => 'AnotherUrl must be correct url.', ]; + $validation->add( [ 'url', @@ -88,15 +115,18 @@ public function validationValidatorUrlMultipleField(IntegrationTester $I) ] ) ); + $messages = $validation->validate( [ 'url' => 'http://google.com', 'anotherUrl' => 'http://google.com', ] ); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $messages->count() + ); $messages = $validation->validate( [ @@ -104,13 +134,16 @@ public function validationValidatorUrlMultipleField(IntegrationTester $I) 'anotherUrl' => 'http://google.com', ] ); - $expected = 1; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $expected = $validationMessages['url']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + $messages->count() + ); + + $I->assertEquals( + $validationMessages['url'], + $messages->offsetGet(0)->getMessage() + ); $messages = $validation->validate( [ @@ -118,17 +151,21 @@ public function validationValidatorUrlMultipleField(IntegrationTester $I) 'anotherUrl' => '://google.', ] ); - $expected = 2; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); - $expected = $validationMessages['url']; - $actual = $messages->offsetGet(0)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 2, + $messages->count() + ); - $expected = $validationMessages['anotherUrl']; - $actual = $messages->offsetGet(1)->getMessage(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $validationMessages['url'], + $messages->offsetGet(0)->getMessage() + ); + + $I->assertEquals( + $validationMessages['anotherUrl'], + $messages->offsetGet(1)->getMessage() + ); } /** @@ -142,6 +179,7 @@ public function validationValidatorUrlMultipleField(IntegrationTester $I) public function validationValidatorUrlCustomMessage(IntegrationTester $I) { $I->wantToTest('Validation\Validator\Url :: validate() - custom message'); + $validation = new Validation(); $validation->add( @@ -153,7 +191,10 @@ public function validationValidatorUrlCustomMessage(IntegrationTester $I) ) ); - $messages = $validation->validate([]); + $messages = $validation->validate( + [] + ); + $expected = new Messages( [ new Message( @@ -164,16 +205,30 @@ public function validationValidatorUrlCustomMessage(IntegrationTester $I) ), ] ); - $actual = $messages; - $I->assertEquals($expected, $actual); - $messages = $validation->validate(['url' => 'x=1']); - $actual = $messages; - $I->assertEquals($expected, $actual); + $I->assertEquals($expected, $messages); + + + + $messages = $validation->validate( + [ + 'url' => 'x=1', + ] + ); + + $I->assertEquals($expected, $messages); + - $messages = $validation->validate(['url' => 'http://phalconphp.com']); - $expected = 0; - $actual = $messages->count(); - $I->assertEquals($expected, $actual); + + $messages = $validation->validate( + [ + 'url' => 'http://phalconphp.com', + ] + ); + + $I->assertEquals( + 0, + $messages->count() + ); } } diff --git a/tests/shim.php b/tests/shim.php index df3c59d81e7..81155354d29 100644 --- a/tests/shim.php +++ b/tests/shim.php @@ -65,15 +65,23 @@ function loadFolders() 'session', 'stream', ]; + foreach ($folders as $folder) { - $item = outputFolder('tests/' . $folder); + $item = outputFolder( + 'tests/' . $folder + ); + if (true !== file_exists($item)) { mkdir($item, 0777, true); } } if (true !== file_exists(cacheFolder())) { - mkdir(cacheFolder(), 0777, true); + mkdir( + cacheFolder(), + 0777, + true + ); } } } diff --git a/tests/testbed/index.php b/tests/testbed/index.php index 135452bed69..a4731480120 100644 --- a/tests/testbed/index.php +++ b/tests/testbed/index.php @@ -6,26 +6,29 @@ use Phalcon\Di\FactoryDefault; $_ENV['APP_DEBUG'] = true; + $debug = new Debug(); + $debug->setBlacklist( [ 'request' => ['some'], 'server' => ['hostname'], ] ); + $debug->listen(); $container = new FactoryDefault(); $x = new C(); + $x->rump(); class C { - function rump() + public function rump() { $return = \Phalcon\Tag::displayTo(false, true); } } - diff --git a/tests/unit/Acl/Adapter/Memory/AddComponentAccessCest.php b/tests/unit/Acl/Adapter/Memory/AddComponentAccessCest.php index 1ddcfe0aaf9..14b22bbb2ae 100644 --- a/tests/unit/Acl/Adapter/Memory/AddComponentAccessCest.php +++ b/tests/unit/Acl/Adapter/Memory/AddComponentAccessCest.php @@ -33,6 +33,7 @@ class AddComponentAccessCest public function aclAdapterMemoryAddComponentAccess(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - addComponentAccess()'); + $I->skipTest('Need implementation'); } @@ -47,11 +48,16 @@ public function aclAdapterMemoryAddComponentAccess(UnitTester $I) public function aclAdapterMemoryAddComponentAccessUnknown(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - addComponentAccess() - unknown'); + $I->expectThrowable( new Exception("Component 'Post' does not exist in ACL"), function () { $acl = new Memory(); - $acl->addComponentAccess('Post', ['update']); + + $acl->addComponentAccess( + 'Post', + ['update'] + ); } ); } @@ -68,12 +74,18 @@ function () { public function aclAdapterMemoryAddComponentAccessWrongAccessList(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - addComponentAccess() - wrong access list'); + $I->expectThrowable( new Exception('Invalid value for accessList'), function () { $acl = new Memory(); $post = new Component('Post'); - $acl->addComponent($post, ['update']); + + $acl->addComponent( + $post, + ['update'] + ); + $acl->addComponentAccess('Post', 123); } ); diff --git a/tests/unit/Acl/Adapter/Memory/AddComponentCest.php b/tests/unit/Acl/Adapter/Memory/AddComponentCest.php index 9a6447046e0..beb24e2b5a0 100644 --- a/tests/unit/Acl/Adapter/Memory/AddComponentCest.php +++ b/tests/unit/Acl/Adapter/Memory/AddComponentCest.php @@ -32,10 +32,15 @@ class AddComponentCest public function aclAdapterMemoryAddComponentString(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - addComponent() - string'); + $acl = new Memory(); $component = new Component('Customer', 'Customer component'); - $actual = $acl->addComponent('Customer', ['index']); + $actual = $acl->addComponent( + 'Customer', + ['index'] + ); + $I->assertTrue($actual); } @@ -50,10 +55,15 @@ public function aclAdapterMemoryAddComponentString(UnitTester $I) public function aclAdapterMemoryAddComponentObject(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - addComponent() - object'); - $acl = new Memory(); + + $acl = new Memory(); $component = new Component('Customer', 'Customer component'); - $actual = $acl->addComponent($component, ['index']); + $actual = $acl->addComponent( + $component, + ['index'] + ); + $I->assertTrue($actual); } @@ -68,12 +78,23 @@ public function aclAdapterMemoryAddComponentObject(UnitTester $I) public function aclAdapterMemoryAddComponentNumericKey(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - addComponent() - numeric key'); - $acl = new Memory(); + + $acl = new Memory(); $component = new Component('11', 'Customer component'); - $actual = $acl->addComponent($component, ['index']); + + + $actual = $acl->addComponent( + $component, + ['index'] + ); + $I->assertTrue($actual); + + + $actual = $acl->isComponent('11'); + $I->assertTrue($actual); } } diff --git a/tests/unit/Acl/Adapter/Memory/AddRoleCest.php b/tests/unit/Acl/Adapter/Memory/AddRoleCest.php index 9e48b1e39b2..781edcd1e73 100644 --- a/tests/unit/Acl/Adapter/Memory/AddRoleCest.php +++ b/tests/unit/Acl/Adapter/Memory/AddRoleCest.php @@ -32,10 +32,14 @@ class AddRoleCest public function aclAdapterMemoryAddRoleString(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - addRole() - string'); - $acl = new Memory(); + + $acl = new Memory(); $role = new Role('Administrators', 'Super User access'); + + $actual = $acl->addRole('Administrators'); + $I->assertTrue($actual); } @@ -50,10 +54,12 @@ public function aclAdapterMemoryAddRoleString(UnitTester $I) public function aclAdapterMemoryAddRoleObject(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - addRole() - object'); - $acl = new Memory(); + + $acl = new Memory(); $role = new Role('Administrators', 'Super User access'); $actual = $acl->addRole($role); + $I->assertTrue($actual); } @@ -68,12 +74,20 @@ public function aclAdapterMemoryAddRoleObject(UnitTester $I) public function aclAdapterMemoryAddRoleTwiceString(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - addRole() - twice string'); - $acl = new Memory(); + + $acl = new Memory(); $role = new Role('Administrators', 'Super User access'); + + $actual = $acl->addRole('Administrators'); + $I->assertTrue($actual); + + + $actual = $acl->addRole('Administrators'); + $I->assertFalse($actual); } @@ -88,12 +102,20 @@ public function aclAdapterMemoryAddRoleTwiceString(UnitTester $I) public function aclAdapterMemoryAddRoleTwiceObject(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - addRole() - twice object'); - $acl = new Memory(); + + $acl = new Memory(); $role = new Role('Administrators', 'Super User access'); + + $actual = $acl->addRole($role); + $I->assertTrue($actual); + + + $actual = $acl->addRole($role); + $I->assertFalse($actual); } @@ -108,12 +130,18 @@ public function aclAdapterMemoryAddRoleTwiceObject(UnitTester $I) public function aclAdapterMemoryAddRoleNumericKey(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - addRole() - numeric key'); - $acl = new Memory(); + + $acl = new Memory(); $role = new Role('11', 'Super User access'); + + $actual = $acl->addRole('11'); + $I->assertTrue($actual); + $actual = $acl->isRole('11'); + $I->assertTrue($actual); } } diff --git a/tests/unit/Acl/Adapter/Memory/AllowCest.php b/tests/unit/Acl/Adapter/Memory/AllowCest.php index 5e71957ccb2..f7e4909cf10 100644 --- a/tests/unit/Acl/Adapter/Memory/AllowCest.php +++ b/tests/unit/Acl/Adapter/Memory/AllowCest.php @@ -35,17 +35,31 @@ class AllowCest public function aclAdapterMemoryAllow(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - allow()'); + $acl = new Memory(); + $acl->setDefaultAction(Acl::DENY); + $acl->addRole('Guests'); $acl->addRole('Member'); - $acl->addComponent('Post', ['update']); + + $acl->addComponent( + 'Post', + ['update'] + ); $acl->allow('Member', 'Post', 'update'); + + $actual = $acl->isAllowed('Guest', 'Post', 'update'); + $I->assertFalse($actual); + + + $actual = $acl->isAllowed('Member', 'Post', 'update'); + $I->assertTrue($actual); } @@ -62,12 +76,19 @@ public function aclAdapterMemoryAllow(UnitTester $I) public function aclAdapterMemoryAllowFunction(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - allow() - function'); + $acl = new Memory(); + $acl->setDefaultAction(Acl::DENY); + $acl->addRole('Guests'); $acl->addRole('Members', 'Guests'); $acl->addRole('Admins', 'Members'); - $acl->addComponent('Post', ['update']); + + $acl->addComponent( + 'Post', + ['update'] + ); $guest = new TestRoleAware(1, 'Guests'); $member = new TestRoleAware(2, 'Members'); @@ -76,6 +97,7 @@ public function aclAdapterMemoryAllowFunction(UnitTester $I) $model = new TestComponentAware(2, 'Post'); $acl->deny('Guests', 'Post', 'update'); + $acl->allow( 'Members', 'Post', @@ -84,18 +106,31 @@ function (TestRoleAware $user, TestComponentAware $model) { return $user->getId() == $model->getUser(); } ); + $acl->allow('Admins', 'Post', 'update'); + + $actual = $acl->isAllowed($guest, $model, 'update'); + $I->assertFalse($actual); + + $actual = $acl->isAllowed($member, $model, 'update'); + $I->assertTrue($actual); + + $actual = $acl->isAllowed($anotherMember, $model, 'update'); + $I->assertFalse($actual); + + $actual = $acl->isAllowed($admin, $model, 'update'); + $I->assertTrue($actual); } diff --git a/tests/unit/Acl/Adapter/Memory/ConstructCest.php b/tests/unit/Acl/Adapter/Memory/ConstructCest.php index 6112dc1821b..dc8b264dde7 100644 --- a/tests/unit/Acl/Adapter/Memory/ConstructCest.php +++ b/tests/unit/Acl/Adapter/Memory/ConstructCest.php @@ -30,6 +30,7 @@ class ConstructCest public function aclAdapterMemoryConstructConstants(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - __construct() - constants'); + $I->assertEquals(1, Acl::ALLOW); $I->assertEquals(0, Acl::DENY); } @@ -45,9 +46,12 @@ public function aclAdapterMemoryConstructConstants(UnitTester $I) public function aclAdapterMemoryConstruct(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - __construct()'); + $acl = new Memory(); - $class = Memory::class; - $I->assertInstanceOf($class, $acl); + $I->assertInstanceOf( + Memory::class, + $acl + ); } } diff --git a/tests/unit/Acl/Adapter/Memory/DenyCest.php b/tests/unit/Acl/Adapter/Memory/DenyCest.php index 34eb7326de7..fa3bc8f722f 100644 --- a/tests/unit/Acl/Adapter/Memory/DenyCest.php +++ b/tests/unit/Acl/Adapter/Memory/DenyCest.php @@ -32,16 +32,26 @@ class DenyCest public function aclAdapterMemoryDeny(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - deny()'); + $acl = new Memory(); - $acl->setDefaultAction(Acl::ALLOW); + + $acl->setDefaultAction( + Acl::ALLOW + ); + $acl->addRole('Guests'); $acl->addRole('Member'); - $acl->addComponent('Post', ['update']); + + $acl->addComponent( + 'Post', + ['update'] + ); $acl->deny('Member', 'Post', 'update'); $actual = $acl->isAllowed('Guest', 'Post', 'update'); $I->assertTrue($actual); + $actual = $acl->isAllowed('Member', 'Post', 'update'); $I->assertFalse($actual); } diff --git a/tests/unit/Acl/Adapter/Memory/GetActiveAccessCest.php b/tests/unit/Acl/Adapter/Memory/GetActiveAccessCest.php index f394519ad77..523e7926c8f 100644 --- a/tests/unit/Acl/Adapter/Memory/GetActiveAccessCest.php +++ b/tests/unit/Acl/Adapter/Memory/GetActiveAccessCest.php @@ -32,8 +32,11 @@ class GetActiveAccessCest public function aclAdapterMemoryGetActiveAccessDefault(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - getActiveAccess() - default'); + $acl = new Memory(); + $actual = $acl->getActiveAccess(); + $I->assertNull($actual); } @@ -48,18 +51,33 @@ public function aclAdapterMemoryGetActiveAccessDefault(UnitTester $I) public function aclAdapterMemoryGetActiveAccess(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - getActiveAccess()'); + $acl = new Memory(); - $acl->setDefaultAction(Acl::DENY); + + $acl->setDefaultAction( + Acl::DENY + ); $acl->addRole('Guests'); - $acl->addComponent('Login', ['help', 'index']); + + $acl->addComponent( + 'Login', + ['help', 'index'] + ); $acl->allow('Guests', 'Login', '*'); + + + $actual = $acl->isAllowed('Guests', 'Login', 'index'); + $I->assertTrue($actual); + + $expected = 'index'; $actual = $acl->getActiveAccess(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/unit/Acl/Adapter/Memory/GetActiveComponentCest.php b/tests/unit/Acl/Adapter/Memory/GetActiveComponentCest.php index 927224ddec1..6f46baa290d 100644 --- a/tests/unit/Acl/Adapter/Memory/GetActiveComponentCest.php +++ b/tests/unit/Acl/Adapter/Memory/GetActiveComponentCest.php @@ -32,8 +32,11 @@ class GetActiveComponentCest public function aclAdapterMemoryGetActiveComponentDefault(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - getActiveComponent() - default'); - $acl = new Memory(); + + $acl = new Memory(); + $actual = $acl->getActiveComponent(); + $I->assertNull($actual); } @@ -48,18 +51,33 @@ public function aclAdapterMemoryGetActiveComponentDefault(UnitTester $I) public function aclAdapterMemoryGetActiveComponent(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - getActiveComponent()'); + $acl = new Memory(); - $acl->setDefaultAction(Acl::DENY); + + $acl->setDefaultAction( + Acl::DENY + ); $acl->addRole('Guests'); - $acl->addComponent('Login', ['help', 'index']); + + $acl->addComponent( + 'Login', + ['help', 'index'] + ); $acl->allow('Guests', 'Login', '*'); + + + $actual = $acl->isAllowed('Guests', 'Login', 'index'); + $I->assertTrue($actual); + + $expected = 'Login'; $actual = $acl->getActiveComponent(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/unit/Acl/Adapter/Memory/GetActiveFunctionCest.php b/tests/unit/Acl/Adapter/Memory/GetActiveFunctionCest.php index 7e39c4cceae..f64f7fa30b1 100644 --- a/tests/unit/Acl/Adapter/Memory/GetActiveFunctionCest.php +++ b/tests/unit/Acl/Adapter/Memory/GetActiveFunctionCest.php @@ -34,26 +34,54 @@ class GetActiveFunctionCest public function aclAdapterMemoryGetActiveFunction(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - getActiveFunction()'); + $function = function ($a) { return true; }; $acl = new Memory(); - $acl->addRole(new Role('Guests')); - $acl->addComponent(new Component('Post'), ['index', 'update', 'create']); + + $acl->addRole( + new Role('Guests') + ); + + $acl->addComponent( + new Component('Post'), + ['index', 'update', 'create'] + ); $acl->allow('Guests', 'Post', 'create', $function); - $I->assertTrue($acl->isAllowed('Guests', 'Post', 'create', ['a' => 1])); + + $I->assertTrue( + $acl->isAllowed( + 'Guests', + 'Post', + 'create', + [ + 'a' => 1, + ] + ) + ); + + + $returnedFunction = $acl->getActiveFunction(); - $I->assertInstanceOf(Closure::class, $returnedFunction); + $I->assertInstanceOf( + Closure::class, + $returnedFunction + ); + + - $expected = 1; - $actual = $function(1); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + $function(1) + ); - $expected = 1; - $actual = $acl->getActiveFunctionCustomArgumentsCount(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + $acl->getActiveFunctionCustomArgumentsCount() + ); } } diff --git a/tests/unit/Acl/Adapter/Memory/GetActiveKeyCest.php b/tests/unit/Acl/Adapter/Memory/GetActiveKeyCest.php index c873858a71e..41d3a37b8a2 100644 --- a/tests/unit/Acl/Adapter/Memory/GetActiveKeyCest.php +++ b/tests/unit/Acl/Adapter/Memory/GetActiveKeyCest.php @@ -33,15 +33,27 @@ class GetActiveKeyCest public function aclAdapterMemoryGetActiveKey(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - getActiveKey()'); + $acl = new Memory(); - $acl->addRole(new Role('Guests')); - $acl->addComponent(new Component('Post'), ['index', 'update', 'create']); + + $acl->addRole( + new Role('Guests') + ); + + $acl->addComponent( + new Component('Post'), + ['index', 'update', 'create'] + ); $acl->allow('Guests', 'Post', 'create'); - $I->assertTrue($acl->isAllowed('Guests', 'Post', 'create')); - $expected = 'Guests!Post!create'; - $actual = $acl->getActiveKey(); - $I->assertEquals($expected, $actual); + $I->assertTrue( + $acl->isAllowed('Guests', 'Post', 'create') + ); + + $I->assertEquals( + 'Guests!Post!create', + $acl->getActiveKey() + ); } } diff --git a/tests/unit/Acl/Adapter/Memory/GetActiveRoleCest.php b/tests/unit/Acl/Adapter/Memory/GetActiveRoleCest.php index 54dd38c858f..bede258b84a 100644 --- a/tests/unit/Acl/Adapter/Memory/GetActiveRoleCest.php +++ b/tests/unit/Acl/Adapter/Memory/GetActiveRoleCest.php @@ -32,8 +32,11 @@ class GetActiveRoleCest public function aclAdapterMemoryGetActiveRoleDefault(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - getActiveRole() - default'); - $acl = new Memory(); + + $acl = new Memory(); + $actual = $acl->getActiveRole(); + $I->assertNull($actual); } @@ -48,18 +51,31 @@ public function aclAdapterMemoryGetActiveRoleDefault(UnitTester $I) public function aclAdapterMemoryGetActiveRole(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - getActiveRole()'); + $acl = new Memory(); - $acl->setDefaultAction(Acl::DENY); + + $acl->setDefaultAction( + Acl::DENY + ); $acl->addRole('Guests'); - $acl->addComponent('Login', ['help', 'index']); + + $acl->addComponent( + 'Login', + ['help', 'index'] + ); $acl->allow('Guests', 'Login', '*'); - $actual = $acl->isAllowed('Guests', 'Login', 'index'); - $I->assertTrue($actual); - $expected = 'Guests'; - $actual = $acl->getActiveRole(); - $I->assertEquals($expected, $actual); + + + $I->assertTrue( + $acl->isAllowed('Guests', 'Login', 'index') + ); + + $I->assertEquals( + 'Guests', + $acl->getActiveRole() + ); } } diff --git a/tests/unit/Acl/Adapter/Memory/GetComponentsCest.php b/tests/unit/Acl/Adapter/Memory/GetComponentsCest.php index a49c423b5b5..85dd46937c5 100644 --- a/tests/unit/Acl/Adapter/Memory/GetComponentsCest.php +++ b/tests/unit/Acl/Adapter/Memory/GetComponentsCest.php @@ -32,6 +32,7 @@ class GetComponentsCest public function aclAdapterMemoryGetComponents(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - getComponents()'); + $acl = new Memory(); $component1 = new Component('Posts'); @@ -40,8 +41,11 @@ public function aclAdapterMemoryGetComponents(UnitTester $I) $acl->addComponent($component1, ['index']); $acl->addComponent($component2, ['index']); + + $expected = [$component1, $component2]; $actual = $acl->getComponents(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/unit/Acl/Adapter/Memory/GetRolesCest.php b/tests/unit/Acl/Adapter/Memory/GetRolesCest.php index e6959452a49..abdb4e2ef2c 100644 --- a/tests/unit/Acl/Adapter/Memory/GetRolesCest.php +++ b/tests/unit/Acl/Adapter/Memory/GetRolesCest.php @@ -32,6 +32,7 @@ class GetRolesCest public function aclAdapterMemoryGetRoles(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - getRoles()'); + $acl = new Memory(); $role1 = new Role('Admin'); @@ -42,6 +43,7 @@ public function aclAdapterMemoryGetRoles(UnitTester $I) $expected = [$role1, $role2]; $actual = $acl->getRoles(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/unit/Acl/Adapter/Memory/GetSetDefaultActionCest.php b/tests/unit/Acl/Adapter/Memory/GetSetDefaultActionCest.php index 67ea575822d..d51276e6d5e 100644 --- a/tests/unit/Acl/Adapter/Memory/GetSetDefaultActionCest.php +++ b/tests/unit/Acl/Adapter/Memory/GetSetDefaultActionCest.php @@ -32,13 +32,17 @@ class GetSetDefaultActionCest public function aclAdapterMemoryGetSetDefaultAction(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - getDefaultAction()/setDefaultAction()'); + $acl = new Memory(); - $acl->setDefaultAction(Acl::ALLOW); + $acl->setDefaultAction( + Acl::ALLOW + ); - $expected = Acl::ALLOW; - $actual = $acl->getDefaultAction(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + Acl::ALLOW, + $acl->getDefaultAction() + ); } /** @@ -52,10 +56,12 @@ public function aclAdapterMemoryGetSetDefaultAction(UnitTester $I) public function aclAdapterMemoryGetSetDefaultActionDefault(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - getDefaultAction()/setDefaultAction() - default'); + $acl = new Memory(); - $expected = Acl::DENY; - $actual = $acl->getDefaultAction(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + Acl::DENY, + $acl->getDefaultAction() + ); } } diff --git a/tests/unit/Acl/Adapter/Memory/GetSetEventsManagerCest.php b/tests/unit/Acl/Adapter/Memory/GetSetEventsManagerCest.php index dead1f23d42..4c516fb977c 100644 --- a/tests/unit/Acl/Adapter/Memory/GetSetEventsManagerCest.php +++ b/tests/unit/Acl/Adapter/Memory/GetSetEventsManagerCest.php @@ -32,14 +32,19 @@ class GetSetEventsManagerCest public function aclAdapterMemoryGetSetEventsManager(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - getEventsManager()/setEventsManager()'); + $acl = new Memory(); $manager = new Manager(); $acl->setEventsManager($manager); $actual = $acl->getEventsManager(); - $class = Manager::class; - $I->assertInstanceOf($class, $actual); + + $I->assertInstanceOf( + Manager::class, + $actual + ); + $I->assertEquals($manager, $actual); } } diff --git a/tests/unit/Acl/Adapter/Memory/GetSetNoArgumentsDefaultActionCest.php b/tests/unit/Acl/Adapter/Memory/GetSetNoArgumentsDefaultActionCest.php index 6780f97e8ce..fc4022dedd8 100644 --- a/tests/unit/Acl/Adapter/Memory/GetSetNoArgumentsDefaultActionCest.php +++ b/tests/unit/Acl/Adapter/Memory/GetSetNoArgumentsDefaultActionCest.php @@ -31,14 +31,20 @@ class GetSetNoArgumentsDefaultActionCest */ public function aclAdapterMemoryGetSetNoArgumentsDefaultAction(UnitTester $I) { - $I->wantToTest('Acl\Adapter\Memory - getNoArgumentsDefaultAction()/setNoArgumentsDefaultAction()'); + $I->wantToTest( + 'Acl\Adapter\Memory - getNoArgumentsDefaultAction()/setNoArgumentsDefaultAction()' + ); + $acl = new Memory(); - $acl->setNoArgumentsDefaultAction(Acl::ALLOW); + $acl->setNoArgumentsDefaultAction( + Acl::ALLOW + ); - $expected = Acl::ALLOW; - $actual = $acl->getNoArgumentsDefaultAction(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + Acl::ALLOW, + $acl->getNoArgumentsDefaultAction() + ); } /** @@ -51,11 +57,15 @@ public function aclAdapterMemoryGetSetNoArgumentsDefaultAction(UnitTester $I) */ public function aclAdapterMemoryGetSetNoArgumentsDefaultActionDefault(UnitTester $I) { - $I->wantToTest('Acl\Adapter\Memory - getNoArgumentsDefaultAction()/setNoArgumentsDefaultAction() - default'); + $I->wantToTest( + 'Acl\Adapter\Memory - getNoArgumentsDefaultAction()/setNoArgumentsDefaultAction() - default' + ); + $acl = new Memory(); - $expected = Acl::DENY; - $actual = $acl->getNoArgumentsDefaultAction(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + Acl::DENY, + $acl->getNoArgumentsDefaultAction() + ); } } diff --git a/tests/unit/Acl/Adapter/Memory/IsAllowedCest.php b/tests/unit/Acl/Adapter/Memory/IsAllowedCest.php index 82ed379d240..87a6edb4eb7 100644 --- a/tests/unit/Acl/Adapter/Memory/IsAllowedCest.php +++ b/tests/unit/Acl/Adapter/Memory/IsAllowedCest.php @@ -87,12 +87,23 @@ public function aclAdapterMemoryIsAllowedObjects(UnitTester $I) public function aclAdapterMemoryIsAllowedSameClass(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - isAllowed() - same class'); + $acl = new Memory(); - $acl->setDefaultAction(Acl::DENY); + + $acl->setDefaultAction( + Acl::DENY + ); + $role = new TestRoleComponentAware(1, 'User', 'Admin'); - $component = new TestRoleComponentAware(2, 'User', 'Admin'); + $component = new TestRoleComponentAware(2, 'User', 'Admin'); + $acl->addRole('Admin'); - $acl->addComponent('User', ['update']); + + $acl->addComponent( + 'User', + ['update'] + ); + $acl->allow( 'Admin', 'User', @@ -102,11 +113,16 @@ function (TestRoleComponentAware $admin, TestRoleComponentAware $user) { } ); - $actual = $acl->isAllowed($role, $component, 'update'); - $I->assertFalse($actual); - $actual = $acl->isAllowed($role, $role, 'update'); - $I->assertTrue($actual); - $actual = $acl->isAllowed($component, $component, 'update'); - $I->assertTrue($actual); + $I->assertFalse( + $acl->isAllowed($role, $component, 'update') + ); + + $I->assertTrue( + $acl->isAllowed($role, $role, 'update') + ); + + $I->assertTrue( + $acl->isAllowed($component, $component, 'update') + ); } } diff --git a/tests/unit/Acl/Adapter/Memory/IsComponentCest.php b/tests/unit/Acl/Adapter/Memory/IsComponentCest.php index d235843547f..4576e4db9df 100644 --- a/tests/unit/Acl/Adapter/Memory/IsComponentCest.php +++ b/tests/unit/Acl/Adapter/Memory/IsComponentCest.php @@ -32,12 +32,15 @@ class IsComponentCest public function aclAdapterMemoryIsComponent(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - isComponent()'); - $acl = new Memory(); + + $acl = new Memory(); $aclComponent = new Component('Customers', 'Customer management'); $acl->addComponent($aclComponent, 'search'); - $actual = $acl->isComponent('Customers'); - $I->assertTrue($actual); + + $I->assertTrue( + $acl->isComponent('Customers') + ); } /** @@ -51,11 +54,14 @@ public function aclAdapterMemoryIsComponent(UnitTester $I) public function aclAdapterMemoryIsComponentUnknown(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - isComponent() - unknown'); - $acl = new Memory(); + + $acl = new Memory(); $aclComponent = new Component('Customers', 'Customer management'); $acl->addComponent($aclComponent, 'search'); - $actual = $acl->isComponent('unknown'); - $I->assertFalse($actual); + + $I->assertFalse( + $acl->isComponent('unknown') + ); } } diff --git a/tests/unit/Acl/Adapter/Memory/IsRoleCest.php b/tests/unit/Acl/Adapter/Memory/IsRoleCest.php index c13af757aec..9bea70b79a8 100644 --- a/tests/unit/Acl/Adapter/Memory/IsRoleCest.php +++ b/tests/unit/Acl/Adapter/Memory/IsRoleCest.php @@ -32,13 +32,15 @@ class IsRoleCest public function aclAdapterMemoryIsRole(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - isRole()'); - $acl = new Memory(); + + $acl = new Memory(); $aclRole = new Role('Administrators', 'Super User access'); $acl->addRole($aclRole); - $actual = $acl->isRole('Administrators'); - $I->assertTrue($actual); + $I->assertTrue( + $acl->isRole('Administrators') + ); } /** @@ -52,12 +54,14 @@ public function aclAdapterMemoryIsRole(UnitTester $I) public function aclAdapterMemoryIsRoleUnknown(UnitTester $I) { $I->wantToTest('Acl\Adapter\Memory - isRole() - unknown'); - $acl = new Memory(); + + $acl = new Memory(); $aclRole = new Role('Administrators', 'Super User access'); $acl->addRole($aclRole); - $actual = $acl->isRole('unknown'); - $I->assertFalse($actual); + $I->assertFalse( + $acl->isRole('unknown') + ); } } diff --git a/tests/unit/Acl/Adapter/MemoryCest.php b/tests/unit/Acl/Adapter/MemoryCest.php index ccd222c681f..1c5796a1f9e 100644 --- a/tests/unit/Acl/Adapter/MemoryCest.php +++ b/tests/unit/Acl/Adapter/MemoryCest.php @@ -28,7 +28,10 @@ class MemoryCest public function testAclWildcardAllowDeny(UnitTester $I) { $acl = new Memory(); - $acl->setDefaultAction(Acl::DENY); + + $acl->setDefaultAction( + Acl::DENY + ); $aclRoles = [ 'Admin' => new Role('Admin'), @@ -46,19 +49,26 @@ public function testAclWildcardAllowDeny(UnitTester $I) } foreach ($aclComponents as $component => $actions) { - $acl->addComponent(new Component($component), $actions); + $acl->addComponent( + new Component($component), + $actions + ); } + $acl->allow("*", "welcome", "index"); foreach ($aclRoles as $Role => $object) { - $actual = $acl->isAllowed($Role, 'welcome', 'index'); - $I->assertTrue($actual); + $I->assertTrue( + $acl->isAllowed($Role, 'welcome', 'index') + ); } $acl->deny("*", "welcome", "index"); + foreach ($aclRoles as $Role => $object) { - $actual = $acl->isAllowed($Role, 'welcome', 'index'); - $I->assertFalse($actual); + $I->assertFalse( + $acl->isAllowed($Role, 'welcome', 'index') + ); } } @@ -74,7 +84,9 @@ public function testAclObjects(UnitTester $I) $aclRole = new Role('Administrators', 'Super User access'); $aclComponent = new Component('Customers', 'Customer management'); - $acl->setDefaultAction(Acl::DENY); + $acl->setDefaultAction( + Acl::DENY + ); $acl->addRole($aclRole); $acl->addComponent($aclComponent, ['search', 'destroy']); @@ -87,20 +99,27 @@ public function testAclObjects(UnitTester $I) $I->assertEquals($expected, $actual); $acl = new Memory(); - $aclRole = new Role('Administrators', 'Super User access'); - $aclComponent = new Component('Customers', 'Customer management'); + $aclRole = new Role('Administrators', 'Super User access'); + $aclComponent = new Component('Customers', 'Customer management'); - $acl->setDefaultAction(Acl::DENY); + $acl->setDefaultAction( + Acl::DENY + ); $acl->addRole($aclRole); - $acl->addComponent($aclComponent, ['search', 'destroy']); + + $acl->addComponent( + $aclComponent, + ['search', 'destroy'] + ); $acl->allow('Administrators', 'Customers', 'search'); $acl->deny('Administrators', 'Customers', 'destroy'); - $expected = Acl::DENY; - $actual = $acl->isAllowed('Administrators', 'Customers', 'destroy'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + Acl::DENY, + $acl->isAllowed('Administrators', 'Customers', 'destroy') + ); } /** @@ -114,8 +133,8 @@ public function testAclSerialize(UnitTester $I) $filename = $I->getNewFileName('acl', 'log'); $acl = new Memory(); - $aclRole = new Role('Administrators', 'Super User access'); - $aclComponent = new Component('Customers', 'Customer management'); + $aclRole = new Role('Administrators', 'Super User access'); + $aclComponent = new Component('Customers', 'Customer management'); $acl->addRole($aclRole); $acl->addComponent($aclComponent, ['search', 'destroy']); @@ -124,11 +143,16 @@ public function testAclSerialize(UnitTester $I) $acl->deny('Administrators', 'Customers', 'destroy'); $contents = serialize($acl); - file_put_contents(cacheFolder($filename), $contents); + file_put_contents( + cacheFolder($filename), + $contents + ); $acl = null; - $contents = file_get_contents(cacheFolder($filename)); + $contents = file_get_contents( + cacheFolder($filename) + ); $I->safeDeleteFile(cacheFolder($filename)); diff --git a/tests/unit/Assets/Asset/SetFilterCest.php b/tests/unit/Assets/Asset/SetFilterCest.php index 0e0c3a92487..55a0c2e33ee 100644 --- a/tests/unit/Assets/Asset/SetFilterCest.php +++ b/tests/unit/Assets/Asset/SetFilterCest.php @@ -55,7 +55,7 @@ public function assetsAssetSetFilterCssFilter(UnitTester $I) public function assetsAssetSetFilterCssRemote(UnitTester $I) { $I->wantToTest('Assets\Asset - setFilter() - css remote'); - $I->skipTest('TODO - Need checking'); + $asset = new Asset('css', 'https://phalcon.ld/css/docs.css'); $expected = true; diff --git a/tests/unit/Assets/Asset/SetLocalCest.php b/tests/unit/Assets/Asset/SetLocalCest.php index eae9df80254..c8deb071312 100644 --- a/tests/unit/Assets/Asset/SetLocalCest.php +++ b/tests/unit/Assets/Asset/SetLocalCest.php @@ -34,10 +34,13 @@ class SetLocalCest public function assetsAssetSetLocalCssLocal(UnitTester $I) { $I->wantToTest('Assets\Asset - setLocal() - css local'); + $asset = new Asset('css', 'https://phalcon.ld/css/docs.css'); $expected = true; + $asset->setLocal($expected); + $this->assetGetLocal($I, $asset, $expected); } @@ -53,10 +56,13 @@ public function assetsAssetSetLocalCssRemote(UnitTester $I) { $I->wantToTest('Assets\Asset - setLocal() - css remote'); $I->skipTest('TODO - Need checking'); + $asset = new Asset('css', 'https://phalcon.ld/css/docs.css'); $expected = false; + $asset->setLocal($expected); + $this->assetGetLocal($I, $asset, $expected); } @@ -71,10 +77,13 @@ public function assetsAssetSetLocalCssRemote(UnitTester $I) public function assetsAssetSetLocalJsLocal(UnitTester $I) { $I->wantToTest('Assets\Asset - setLocal() - js local'); + $asset = new Asset('js', 'https://phalcon.ld/js/jquery.js'); $expected = true; + $asset->setLocal($expected); + $this->assetGetLocal($I, $asset, $expected); } @@ -90,10 +99,13 @@ public function assetsAssetSetLocalJsRemote(UnitTester $I) { $I->wantToTest('Assets\Asset - setLocal() - js remote'); $I->skipTest('TODO - Need checking'); + $asset = new Asset('js', 'https://phalcon.ld/js/jquery.js'); $expected = false; + $asset->setLocal($expected); + $this->assetGetLocal($I, $asset, $expected); } } diff --git a/tests/unit/Assets/Manager/OutputJsCest.php b/tests/unit/Assets/Manager/OutputJsCest.php index 867f93f66d3..5d27344f20a 100644 --- a/tests/unit/Assets/Manager/OutputJsCest.php +++ b/tests/unit/Assets/Manager/OutputJsCest.php @@ -54,18 +54,24 @@ public function _before(UnitTester $I) public function assetsManagerOutputJsImplicit(UnitTester $I) { $I->wantToTest('Assets\Manager - outputJs() - implicit'); + $assets = new Manager(); $assets->addJs('js/script1.js'); $assets->addJs('js/script2.js'); - $assets->addAsset(new Js('/js/script3.js', false)); + + $assets->addAsset( + new Js('/js/script3.js', false) + ); $expected = '' . PHP_EOL . '' . PHP_EOL . '' . PHP_EOL; $assets->useImplicitOutput(false); + $actual = $assets->outputJs(); + $I->assertEquals($expected, $actual); } @@ -80,19 +86,25 @@ public function assetsManagerOutputJsImplicit(UnitTester $I) public function assetsManagerOutputJsNotImplicit(UnitTester $I) { $I->wantToTest('Assets\Manager - outputJs() - not implicit'); + $assets = new Manager(); $assets->addJs('js/script1.js'); $assets->addJs('js/script2.js'); - $assets->addAsset(new Js('/js/script3.js', false)); - $expected = '' . PHP_EOL - . '' . PHP_EOL - . '' . PHP_EOL; + $assets->addAsset( + new Js( + '/js/script3.js', + false + ) + ); + + $expected = '' . PHP_EOL . '' . PHP_EOL . '' . PHP_EOL; ob_start(); $assets->outputJs(); $actual = ob_get_clean(); + $I->assertEquals($expected, $actual); } @@ -106,14 +118,22 @@ public function assetsManagerOutputJsCustomTag(UnitTester $I) $I->wantToTest('Asset/Manager - outputJs() - custom tag component'); $di = $this->getDi(); - $di->setShared('tag', CustomTag::class); + + $di->setShared( + 'tag', + CustomTag::class + ); $assets = new Manager(); + $assets->setDI($di); $assets->addJs('js/script1.js'); $assets->addJs('/js/script2.js'); - $assets->addAsset(new Js('/js/script3.js')); + + $assets->addAsset( + new Js('/js/script3.js') + ); $expected = '' . PHP_EOL . '' . PHP_EOL @@ -122,6 +142,7 @@ public function assetsManagerOutputJsCustomTag(UnitTester $I) ob_start(); $assets->outputJs(); $actual = ob_get_clean(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/unit/Assets/ManagerCest.php b/tests/unit/Assets/ManagerCest.php index d97d948c6c6..2eef02c6a0e 100644 --- a/tests/unit/Assets/ManagerCest.php +++ b/tests/unit/Assets/ManagerCest.php @@ -62,29 +62,39 @@ public function testAssetsManagerAddingCssAndJs(UnitTester $I) $collectionCss = $assets->get('css'); $collectionJs = $assets->get('js'); + + $CSSnumber = 0; - $expected = 'css'; + foreach ($collectionCss as $resource) { $actual = $resource->getType(); - $I->assertEquals($expected, $actual); + + $I->assertEquals('css', $actual); + $CSSnumber++; } - $expected = 2; - $actual = $CSSnumber; - $I->assertEquals($expected, $actual); + $I->assertEquals( + 2, + $CSSnumber + ); + + $JSnumber = 0; - $expected = 'js'; + foreach ($collectionJs as $resource) { $actual = $resource->getType(); - $I->assertEquals($expected, $actual); + + $I->assertEquals('js', $actual); + $JSnumber++; } - $expected = 2; - $actual = $JSnumber; - $I->assertEquals($expected, $actual); + $I->assertEquals( + 2, + $JSnumber + ); } /** @@ -96,9 +106,11 @@ public function testAssetsManagerAddingCssAndJs(UnitTester $I) public function testAssetsManagerOutputCssWithoutImplicitOutputFromCollection(UnitTester $I) { $assets = new Manager(); + $assets->collection('footer')->addCss('css/style1.css'); $footer = $assets->collection('footer'); + $footer->addCss('css/style2.css'); $expected = sprintf( @@ -108,8 +120,11 @@ public function testAssetsManagerOutputCssWithoutImplicitOutputFromCollection(Un ); $assets->useImplicitOutput(false); - $actual = $assets->outputCss('footer'); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $expected, + $assets->outputCss('footer') + ); } /** @@ -131,14 +146,17 @@ public function testAssetsManagerOutputJsWithoutImplicitOutputFromCollectionRemo ; $assets->useImplicitOutput(false); - $actual = $assets->outputJs('header'); $expected = sprintf( "%s\n%s\n", '', '' ); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $expected, + $assets->outputJs('header') + ); } /** @@ -160,23 +178,34 @@ public function testAssetsManagerOutputJsWithMixedAssetCollection(UnitTester $I) ->addCss('css/styles1.css') ->addCss('css/styles2.css') ; + $assets->useImplicitOutput(false); - $actualJS = $assets->outputJs('header'); + + $expectedJS = sprintf( "%s\n%s\n", '', '' ); - $I->assertEquals($expectedJS, $actualJS); - $actualCSS = $assets->outputCss('header'); + $I->assertEquals( + $expectedJS, + $assets->outputJs('header') + ); + + + $expectedCSS = sprintf( "%s\n%s\n", '', '' ); - $I->assertEquals($expectedCSS, $actualCSS); + + $I->assertEquals( + $expectedCSS, + $assets->outputCss('header') + ); } /** @@ -189,11 +218,14 @@ public function testAssetsManagerOutputJsWithMixedAssetCollection(UnitTester $I) */ public function testTargetLocal(UnitTester $I) { - $file = uniqid() . '.js'; + $file = uniqid() . '.js'; + $assets = new Manager(); + $jsFile = dataFolder('assets/assets/jquery.js'); $assets->useImplicitOutput(false); + $assets->collection('js') ->addJs($jsFile) ->join(true) @@ -204,12 +236,18 @@ public function testTargetLocal(UnitTester $I) ->setTargetUri('js/jquery.js') ; - $expected = '' . PHP_EOL; - $actual = $assets->outputJs('js'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + '' . PHP_EOL, + $assets->outputJs('js') + ); - $I->seeFileFound(outputFolder("tests/assets/{$file}")); - $I->safeDeleteFile(outputFolder("tests/assets/{$file}")); + $I->seeFileFound( + outputFolder("tests/assets/{$file}") + ); + + $I->safeDeleteFile( + outputFolder("tests/assets/{$file}") + ); } /** @@ -223,6 +261,7 @@ public function testBasicOutput(UnitTester $I) $assets = new Manager(); $assets->useImplicitOutput(false); + $assets->collection('js') ->addJs(dataFolder('assets/assets/jquery.js'), false, false) ->setTargetPath(outputFolder("tests/assets/combined.js")) @@ -234,8 +273,11 @@ public function testBasicOutput(UnitTester $I) dataFolder('assets/assets/jquery.js'), PHP_EOL ); - $actual = $assets->outputJs('js'); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $expected, + $assets->outputJs('js') + ); } /** @@ -249,6 +291,7 @@ public function testOutputWithEnabledJoin(UnitTester $I) $assets = new Manager(); $assets->useImplicitOutput(false); + $assets->collection('js') ->addJs(dataFolder('assets/assets/jquery.js'), false, false) ->setTargetPath(outputFolder("tests/assets/combined.js")) @@ -261,8 +304,11 @@ public function testOutputWithEnabledJoin(UnitTester $I) dataFolder('assets/assets/jquery.js'), PHP_EOL ); - $actual = $assets->outputJs('js'); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $expected, + $assets->outputJs('js') + ); } /** @@ -276,6 +322,7 @@ public function testOutputWithDisabledJoin(UnitTester $I) $assets = new Manager(); $assets->useImplicitOutput(false); + $assets->collection('js') ->addJs(dataFolder('assets/assets/jquery.js'), false, false) ->setTargetPath(outputFolder("assets/combined.js")) @@ -288,8 +335,11 @@ public function testOutputWithDisabledJoin(UnitTester $I) dataFolder('assets/assets/jquery.js'), PHP_EOL ); - $actual = $assets->outputJs('js'); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $expected, + $assets->outputJs('js') + ); } /** @@ -301,8 +351,11 @@ public function testOutputWithDisabledJoin(UnitTester $I) public function testOutputWithJoinAndFilter(UnitTester $I) { $assets = new Manager(); + $jsFile = dataFolder('assets/assets/jquery.js'); + $assets->useImplicitOutput(false); + $assets->collection('js') ->addJs($jsFile, false, false) ->setTargetPath(outputFolder("assets/combined.js")) @@ -316,8 +369,11 @@ public function testOutputWithJoinAndFilter(UnitTester $I) dataFolder('assets/assets/jquery.js'), PHP_EOL ); - $actual = $assets->outputJs('js'); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $expected, + $assets->outputJs('js') + ); } /** @@ -329,14 +385,17 @@ public function addInlineJs(UnitTester $I) $manager = new Manager(); $jsFile = dataFolder('assets/assets/signup.js'); $js = file_get_contents($jsFile); + $manager->addInlineJs($js); - $expected = "\n"; ob_start(); $manager->outputInlineJs(); $actual = ob_get_contents(); ob_end_clean(); - $I->assertSame($expected, $actual); + $I->assertEquals( + "\n", + $actual + ); } } diff --git a/tests/unit/Collection/ClearCest.php b/tests/unit/Collection/ClearCest.php index 8d9c9a84e66..445eef77c92 100644 --- a/tests/unit/Collection/ClearCest.php +++ b/tests/unit/Collection/ClearCest.php @@ -31,20 +31,25 @@ class ClearCest public function collectionClear(UnitTester $I) { $I->wantToTest('Collection - clear()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Collection($data); - $expected = $data; - $actual = $collection->toArray(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $data, + $collection->toArray() + ); $collection->clear(); - $expected = 0; - $actual = $collection->count(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 0, + $collection->count() + ); } } diff --git a/tests/unit/Collection/GetCest.php b/tests/unit/Collection/GetCest.php index 787f91fc12c..c3ecc3fb874 100644 --- a/tests/unit/Collection/GetCest.php +++ b/tests/unit/Collection/GetCest.php @@ -31,27 +31,40 @@ class GetCest public function collectionGet(UnitTester $I) { $I->wantToTest('Collection - get()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Collection($data); $expected = 'four'; - $actual = $collection->get('three'); - $I->assertEquals($expected, $actual); - $actual = $collection->get('THREE'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $collection->get('three') + ); + + $I->assertEquals( + $expected, + $collection->get('THREE') + ); - $actual = $collection['three']; - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $collection['three'] + ); - $actual = $collection->three; - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $collection->three + ); - $actual = $collection->offsetGet('three'); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $expected, + $collection->offsetGet('three') + ); } } diff --git a/tests/unit/Collection/GetIteratorCest.php b/tests/unit/Collection/GetIteratorCest.php index 9c61c1d2a24..350fa8bb3c7 100644 --- a/tests/unit/Collection/GetIteratorCest.php +++ b/tests/unit/Collection/GetIteratorCest.php @@ -31,15 +31,20 @@ class GetIteratorCest public function collectionGetIterator(UnitTester $I) { $I->wantToTest('Collection - getIterator()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Collection($data); foreach ($collection as $key => $value) { - $I->assertEquals($data[$key], $collection[$key]); + $I->assertEquals( + $data[$key], + $collection[$key] + ); } } } diff --git a/tests/unit/Collection/HasCest.php b/tests/unit/Collection/HasCest.php index 79234fb0a04..6ef3d4881ca 100644 --- a/tests/unit/Collection/HasCest.php +++ b/tests/unit/Collection/HasCest.php @@ -31,35 +31,45 @@ class HasCest public function collectionHas(UnitTester $I) { $I->wantToTest('Collection - has()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Collection($data); - $actual = $collection->has('three'); - $I->assertTrue($actual); + $I->assertTrue( + $collection->has('three') + ); - $actual = $collection->has('THREE'); - $I->assertTrue($actual); + $I->assertTrue( + $collection->has('THREE') + ); - $actual = $collection->has('THREE', false); - $I->assertFalse($actual); + $I->assertFalse( + $collection->has('THREE', false) + ); - $actual = $collection->has('unknown'); - $I->assertFalse($actual); + $I->assertFalse( + $collection->has('unknown') + ); - $actual = isset($collection['three']); - $I->assertTrue($actual); + $I->assertTrue( + isset($collection['three']) + ); - $actual = isset($collection['unknown']); - $I->assertFalse($actual); + $I->assertFalse( + isset($collection['unknown']) + ); - $actual = $collection->offsetExists('three'); - $I->assertTrue($actual); + $I->assertTrue( + $collection->offsetExists('three') + ); - $actual = $collection->offsetExists('unknown'); - $I->assertFalse($actual); + $I->assertFalse( + $collection->offsetExists('unknown') + ); } } diff --git a/tests/unit/Collection/InitCest.php b/tests/unit/Collection/InitCest.php index e4cf987ca2b..a0f40d62be8 100644 --- a/tests/unit/Collection/InitCest.php +++ b/tests/unit/Collection/InitCest.php @@ -31,6 +31,7 @@ class InitCest public function collectionInit(UnitTester $I) { $I->wantToTest('Collection - init()'); + $data = [ 'one' => 'two', 'three' => 'four', @@ -39,13 +40,16 @@ public function collectionInit(UnitTester $I) $collection = new Collection(); - $expected = 0; - $actual = $collection->count(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 0, + $collection->count() + ); $collection->init($data); - $expected = $data; - $actual = $collection->toArray(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $data, + $collection->toArray() + ); } } diff --git a/tests/unit/Collection/JsonSerializeCest.php b/tests/unit/Collection/JsonSerializeCest.php index b3c8da20caa..27c08aa3fcb 100644 --- a/tests/unit/Collection/JsonSerializeCest.php +++ b/tests/unit/Collection/JsonSerializeCest.php @@ -31,15 +31,18 @@ class JsonSerializeCest public function collectionJsonSerialize(UnitTester $I) { $I->wantToTest('Collection - jsonSerialize()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Collection($data); - $expected = $data; - $actual = $collection->jsonSerialize(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $data, + $collection->jsonSerialize() + ); } } diff --git a/tests/unit/Collection/RemoveCest.php b/tests/unit/Collection/RemoveCest.php index 4c8bca08ee1..31f961085f8 100644 --- a/tests/unit/Collection/RemoveCest.php +++ b/tests/unit/Collection/RemoveCest.php @@ -31,49 +31,64 @@ class RemoveCest public function collectionRemove(UnitTester $I) { $I->wantToTest('Collection - remove()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Collection($data); - $expected = $data; - $actual = $collection->toArray(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $data, + $collection->toArray() + ); $collection->remove('five'); - $expected = [ - 'one' => 'two', - 'three' => 'four', - ]; - $actual = $collection->toArray(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + [ + 'one' => 'two', + 'three' => 'four', + ], + $collection->toArray() + ); $collection->remove('FIVE'); - $expected = [ - 'one' => 'two', - 'three' => 'four', - ]; - $actual = $collection->toArray(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + [ + 'one' => 'two', + 'three' => 'four', + ], + $collection->toArray() + ); $collection->init($data); - unset($collection['five']); - $expected = [ - 'one' => 'two', - 'three' => 'four', - ]; - $actual = $collection->toArray(); - $I->assertEquals($expected, $actual); + + unset( + $collection['five'] + ); + + $I->assertEquals( + [ + 'one' => 'two', + 'three' => 'four', + ], + $collection->toArray() + ); $collection->init($data); + $collection->offsetUnset('five'); - $expected = [ - 'one' => 'two', - 'three' => 'four', - ]; - $actual = $collection->toArray(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + [ + 'one' => 'two', + 'three' => 'four', + ], + $collection->toArray() + ); } } diff --git a/tests/unit/Collection/SerializeCest.php b/tests/unit/Collection/SerializeCest.php index d7e39fee33b..704593a227e 100644 --- a/tests/unit/Collection/SerializeCest.php +++ b/tests/unit/Collection/SerializeCest.php @@ -31,15 +31,18 @@ class SerializeCest public function collectionSerialize(UnitTester $I) { $I->wantToTest('Collection - serialize()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Collection($data); - $expected = serialize($data); - $actual = $collection->serialize(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + serialize($data), + $collection->serialize() + ); } } diff --git a/tests/unit/Collection/SetCest.php b/tests/unit/Collection/SetCest.php index 108073303bc..e0a6ba6aaed 100644 --- a/tests/unit/Collection/SetCest.php +++ b/tests/unit/Collection/SetCest.php @@ -31,25 +31,36 @@ class SetCest public function collectionSet(UnitTester $I) { $I->wantToTest('Collection - set()'); + $collection = new Collection(); $collection->set('three', 'two'); - $expected = 'two'; - $actual = $collection->get('three'); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 'two', + $collection->get('three') + ); $collection->three = 'Phalcon'; - $expected = 'Phalcon'; - $actual = $collection->get('three'); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 'Phalcon', + $collection->get('three') + ); $collection->offsetSet('three', 123); - $expected = 123; - $actual = $collection->get('three'); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + 123, + $collection->get('three') + ); + + $collection['three'] = true; - $actual = $collection->get('three'); - $I->assertTrue($actual); + + $I->assertTrue( + $collection->get('three') + ); } } diff --git a/tests/unit/Collection/ToArrayCest.php b/tests/unit/Collection/ToArrayCest.php index 029e7c74962..0bc9697b13e 100644 --- a/tests/unit/Collection/ToArrayCest.php +++ b/tests/unit/Collection/ToArrayCest.php @@ -31,15 +31,18 @@ class ToArrayCest public function collectionToArray(UnitTester $I) { $I->wantToTest('Collection - toArray()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Collection($data); - $expected = $data; - $actual = $collection->toArray(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $data, + $collection->toArray() + ); } } diff --git a/tests/unit/Collection/ToJsonCest.php b/tests/unit/Collection/ToJsonCest.php index 449353e7e41..81842b8b3cb 100644 --- a/tests/unit/Collection/ToJsonCest.php +++ b/tests/unit/Collection/ToJsonCest.php @@ -31,19 +31,23 @@ class ToJsonCest public function collectionToJson(UnitTester $I) { $I->wantToTest('Collection - toJson()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $collection = new Collection($data); - $expected = json_encode($data); - $actual = $collection->toJson(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + json_encode($data), + $collection->toJson() + ); - $expected = json_encode($data, JSON_PRETTY_PRINT); - $actual = $collection->toJson(JSON_PRETTY_PRINT); - $I->assertEquals($expected, $actual); + $I->assertEquals( + json_encode($data, JSON_PRETTY_PRINT), + $collection->toJson(JSON_PRETTY_PRINT) + ); } } diff --git a/tests/unit/Collection/UnserializeCest.php b/tests/unit/Collection/UnserializeCest.php index ec1367c3f88..82a96d55fc1 100644 --- a/tests/unit/Collection/UnserializeCest.php +++ b/tests/unit/Collection/UnserializeCest.php @@ -31,17 +31,22 @@ class UnserializeCest public function collectionSerialize(UnitTester $I) { $I->wantToTest('Collection - serialize()'); - $data = [ + + $data = [ 'one' => 'two', 'three' => 'four', 'five' => 'six', ]; + $serialized = serialize($data); + $collection = new Collection(); $collection->unserialize($serialized); - $expected = $data; - $actual = $collection->toArray(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $data, + $collection->toArray() + ); } } diff --git a/tests/unit/Config/ConfigCest.php b/tests/unit/Config/ConfigCest.php index 2422ef9e353..d4daa2737c0 100644 --- a/tests/unit/Config/ConfigCest.php +++ b/tests/unit/Config/ConfigCest.php @@ -27,11 +27,16 @@ class ConfigCest */ public function testNumericConfig(UnitTester $I) { - $config = new Config(['abc']); + $config = new Config( + [ + 'abc', + ] + ); - $expected = 'abc'; - $actual = $config->{0}; - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'abc', + $config->{0} + ); } /** @@ -48,17 +53,20 @@ public function testChildArrayToConfigObject(UnitTester $I) ] ); - $expected = 'Phalcon\Config'; - $actual = $config->childNode; - $I->assertInstanceOf($expected, $actual); + $I->assertInstanceOf( + Config::class, + $config->childNode + ); - $expected = 'Phalcon\Config'; - $actual = $config->get('childNode'); - $I->assertInstanceOf($expected, $actual); + $I->assertInstanceOf( + Config::class, + $config->get('childNode') + ); - $expected = 'Phalcon\Config'; - $actual = $config->offsetGet('childNode'); - $I->assertInstanceOf($expected, $actual); + $I->assertInstanceOf( + Config::class, + $config->offsetGet('childNode') + ); } /** @@ -99,7 +107,9 @@ public function testStandardConfigSimpleArray(UnitTester $I) ], ] ); - $actual = new Config($settings); + + $actual = new Config($settings); + $I->assertEquals($expected, $actual); } @@ -111,7 +121,14 @@ public function testStandardConfigSimpleArray(UnitTester $I) */ public function testConfigMergeArray(UnitTester $I) { - $config = new Config(['keys' => ['scott', 'cheetah']]); + $config = new Config( + [ + 'keys' => [ + 'scott', + 'cheetah', + ], + ] + ); $expected = Config::__set_state( [ @@ -124,19 +141,46 @@ public function testConfigMergeArray(UnitTester $I) ), ] ); - $actual = $config->merge(new Config(['keys' => ['peter']])); + + $actual = $config->merge( + new Config( + [ + 'keys' => ['peter'], + ] + ) + ); + $I->assertEquals($expected, $actual); - $config = new Config(['keys' => ['peter']]); + $config = new Config( + [ + 'keys' => ['peter'], + ] + ); + + $expected = Config::__set_state( + [ + 'keys' => Config::__set_state( + [ + '0' => 'peter', + '1' => 'scott', + '2' => 'cheetah', + ] + ), + ] + ); + + $actual = $config->merge( + new Config( + [ + 'keys' => [ + 'scott', + 'cheetah', + ], + ] + ) + ); - $expected = Config::__set_state([ - 'keys' => Config::__set_state([ - '0' => 'peter', - '1' => 'scott', - '2' => 'cheetah', - ]), - ]); - $actual = $config->merge(new Config(['keys' => ['scott', 'cheetah']])); $I->assertEquals($expected, $actual); } @@ -148,41 +192,45 @@ public function testConfigMergeArray(UnitTester $I) */ public function testConfigMergeComplexObjects(UnitTester $I) { - $config1 = new Config([ - 'controllersDir' => '../x/y/z', - 'modelsDir' => '../x/y/z', - 'database' => [ - 'adapter' => 'Mysql', - 'host' => 'localhost', - 'username' => 'scott', - 'password' => 'cheetah', - 'name' => 'test_db', - 'charset' => [ - 'primary' => 'utf8', - ], - 'alternatives' => [ - 'primary' => 'latin1', - 'second' => 'latin1', - ], - ], - ]); - - $config2 = new Config([ - 'modelsDir' => '../x/y/z', - 'database' => [ - 'adapter' => 'Postgresql', - 'host' => 'localhost', - 'username' => 'peter', - 'options' => [ - 'case' => 'lower', - \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', + $config1 = new Config( + [ + 'controllersDir' => '../x/y/z', + 'modelsDir' => '../x/y/z', + 'database' => [ + 'adapter' => 'Mysql', + 'host' => 'localhost', + 'username' => 'scott', + 'password' => 'cheetah', + 'name' => 'test_db', + 'charset' => [ + 'primary' => 'utf8', + ], + 'alternatives' => [ + 'primary' => 'latin1', + 'second' => 'latin1', + ], ], - 'alternatives' => [ - 'primary' => 'swedish', - 'third' => 'american', + ] + ); + + $config2 = new Config( + [ + 'modelsDir' => '../x/y/z', + 'database' => [ + 'adapter' => 'Postgresql', + 'host' => 'localhost', + 'username' => 'peter', + 'options' => [ + 'case' => 'lower', + \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', + ], + 'alternatives' => [ + 'primary' => 'swedish', + 'third' => 'american', + ], ], - ], - ]); + ] + ); $config1->merge($config2); @@ -219,7 +267,9 @@ public function testConfigMergeComplexObjects(UnitTester $I) ), ] ); - $actual = $config1; + + $actual = $config1; + $I->assertEquals($expected, $actual); } @@ -263,7 +313,9 @@ public function testIssue12779(UnitTester $I) ], ], ]; - $actual = $config->toArray(); + + $actual = $config->toArray(); + $I->assertEquals($expected, $actual); } @@ -276,51 +328,116 @@ public function testIssue12779(UnitTester $I) */ public function testIssue13351MergeNonZeroBasedNumericKey(UnitTester $I) { - $config = new Config([1 => 'Apple']); - $config2 = new Config([2 => 'Banana']); + $config = new Config( + [ + 1 => 'Apple', + ] + ); + + $config2 = new Config( + [ + 2 => 'Banana', + ] + ); + $config->merge($config2); + + $expected = [ 1 => 'Apple', 2 => 'Banana', ]; - $actual = $config->toArray(); + + $actual = $config->toArray(); + $I->assertEquals($expected, $actual); - $config = new Config([0 => 'Apple']); - $config2 = new Config([1 => 'Banana']); + + $config = new Config( + [ + 0 => 'Apple', + ] + ); + + $config2 = new Config( + [ + 1 => 'Banana', + ] + ); + $config->merge($config2); + + $expected = [ 0 => 'Apple', 1 => 'Banana', ]; - $actual = $config->toArray(); + + $actual = $config->toArray(); + $I->assertEquals($expected, $actual); - $config = new Config([1 => 'Apple', 'p' => 'Pineapple']); - $config2 = new Config([2 => 'Banana']); + + + $config = new Config( + [ + 1 => 'Apple', + 'p' => 'Pineapple', + ] + ); + + $config2 = new Config( + [ + 2 => 'Banana', + ] + ); + $config->merge($config2); + + $expected = [ 1 => 'Apple', 'p' => 'Pineapple', 2 => 'Banana', ]; - $actual = $config->toArray(); + + $actual = $config->toArray(); + $I->assertEquals($expected, $actual); - $config = new Config([ - 'One' => [1 => 'Apple', 'p' => 'Pineapple'], - 'Two' => [1 => 'Apple'], - ]); - $config2 = new Config([ - 'One' => [2 => 'Banana'], - 'Two' => [2 => 'Banana'], - ]); + + + $config = new Config( + [ + 'One' => [ + 1 => 'Apple', + 'p' => 'Pineapple', + ], + 'Two' => [ + 1 => 'Apple', + ], + ] + ); + + $config2 = new Config( + [ + 'One' => [ + 2 => 'Banana', + ], + 'Two' => [ + 2 => 'Banana', + ], + ] + ); + $config->merge($config2); + + $expected = [ 'One' => [ 1 => 'Apple', @@ -332,7 +449,9 @@ public function testIssue13351MergeNonZeroBasedNumericKey(UnitTester $I) 2 => 'Banana', ], ]; - $actual = $config->toArray(); + + $actual = $config->toArray(); + $I->assertEquals($expected, $actual); } } diff --git a/tests/unit/Config/MergeCest.php b/tests/unit/Config/MergeCest.php index 11c7388b546..d93bffe2534 100644 --- a/tests/unit/Config/MergeCest.php +++ b/tests/unit/Config/MergeCest.php @@ -34,10 +34,12 @@ class MergeCest public function configMergeConfig(UnitTester $I) { $I->wantToTest("Config - merge() - Config"); + $config = $this->getConfig(); $expected = $this->getMergedByConfig(); $actual = $config; + $I->assertEquals($expected, $actual); } @@ -52,10 +54,12 @@ public function configMergeConfig(UnitTester $I) public function configMergeArr(UnitTester $I) { $I->wantToTest("Config - merge() - array"); + $config = $this->getConfig(); $expected = $this->getMergedByArray(); $actual = $config; + $I->assertEquals($expected, $actual); } @@ -67,7 +71,10 @@ public function configMergeArr(UnitTester $I) private function getMergedByConfig(): Config { $config = new Config(); - $config->merge($this->getConfig()); + + $config->merge( + $this->getConfig() + ); return $config; } @@ -80,7 +87,10 @@ private function getMergedByConfig(): Config private function getMergedByArray(): Config { $config = new Config(); - $config->merge(require dataFolder('assets/config/config.php')); + + $config->merge( + require dataFolder('assets/config/config.php') + ); return $config; } diff --git a/tests/unit/Config/PathCest.php b/tests/unit/Config/PathCest.php index 3eac3cc6a86..65d35865f79 100644 --- a/tests/unit/Config/PathCest.php +++ b/tests/unit/Config/PathCest.php @@ -33,6 +33,7 @@ class PathCest public function configPath(UnitTester $I) { $I->wantToTest('Config - path()'); + $this->checkPath($I); } @@ -45,6 +46,7 @@ public function configPath(UnitTester $I) public function configPathDefault(UnitTester $I) { $I->wantToTest('Config - path() - default'); + $this->checkPathDefault($I); } } diff --git a/tests/unit/Config/SetStateCest.php b/tests/unit/Config/SetStateCest.php index 243d102c4fc..64147493f2b 100644 --- a/tests/unit/Config/SetStateCest.php +++ b/tests/unit/Config/SetStateCest.php @@ -34,11 +34,13 @@ class SetStateCest public function configSetState(UnitTester $I) { $I->wantToTest("Config - __set_state()"); + $config = $this->getConfig(); - $expected = $this->getSetState(); - $actual = $config; - $I->assertEquals($expected, $actual); + $I->assertEquals( + $this->getSetState(), + $config + ); } /** diff --git a/tests/unit/Config/ToArrayCest.php b/tests/unit/Config/ToArrayCest.php index d383c348139..a7397cc10e3 100644 --- a/tests/unit/Config/ToArrayCest.php +++ b/tests/unit/Config/ToArrayCest.php @@ -33,6 +33,7 @@ class ToArrayCest public function configToArray(UnitTester $I) { $I->wantToTest("Config - toArray()"); + $this->checkToArray($I); } } diff --git a/tests/unit/Crypt/ConstructCest.php b/tests/unit/Crypt/ConstructCest.php index 2443a5c3902..1b577aeee4d 100644 --- a/tests/unit/Crypt/ConstructCest.php +++ b/tests/unit/Crypt/ConstructCest.php @@ -31,13 +31,24 @@ class ConstructCest public function cryptConstruct(UnitTester $I) { $I->wantToTest('Crypt - __construct()'); - $actual = new Crypt(); - $class = Crypt::class; - $I->assertInstanceOf($class, $actual); - $actual = new Crypt("aes-256-cfb", true); - $class = Crypt::class; - $I->assertInstanceOf($class, $actual); + + + $crypt = new Crypt(); + + $I->assertInstanceOf( + Crypt::class, + $crypt + ); + + + + $crypt = new Crypt("aes-256-cfb", true); + + $I->assertInstanceOf( + Crypt::class, + $crypt + ); } /** diff --git a/tests/unit/Crypt/DecryptCest.php b/tests/unit/Crypt/DecryptCest.php index dedb8d20dfb..3a35f639508 100644 --- a/tests/unit/Crypt/DecryptCest.php +++ b/tests/unit/Crypt/DecryptCest.php @@ -31,6 +31,7 @@ class DecryptCest public function shouldNotThrowExceptionIfKeyMismatch(UnitTester $I) { $I->wantToTest('Crypt - decrypt() not throwing Exception on key mismatch'); + $crypt = new Crypt(); $actual = $crypt->decrypt( @@ -57,6 +58,7 @@ public function shouldThrowExceptionIfHashMismatch(UnitTester $I) Exception::class, function () { $crypt = new Crypt(); + $crypt->useSigning(true); $crypt->decrypt( @@ -77,6 +79,7 @@ function () { public function shouldDecryptSignedString(UnitTester $I) { $crypt = new Crypt(); + $crypt->useSigning(true); $key = 'secret'; diff --git a/tests/unit/Crypt/EncryptCest.php b/tests/unit/Crypt/EncryptCest.php index fed0c4cfafe..e48d965f451 100644 --- a/tests/unit/Crypt/EncryptCest.php +++ b/tests/unit/Crypt/EncryptCest.php @@ -31,11 +31,13 @@ class EncryptCest public function cryptEncrypt(UnitTester $I) { $I->wantToTest('Crypt - encrypt()'); - $tests = [ + + $tests = [ md5(uniqid()) => str_repeat('x', mt_rand(1, 255)), time() . time() => str_shuffle('abcdefeghijklmnopqrst'), 'le$ki12432543543543543' => "", ]; + $ciphers = [ 'AES-128-ECB', 'AES-128-CBC', @@ -45,19 +47,39 @@ public function cryptEncrypt(UnitTester $I) ]; $crypt = new Crypt(); + foreach ($ciphers as $cipher) { $crypt->setCipher($cipher); foreach ($tests as $key => $test) { - $crypt->setKey(substr($key, 0, 16)); + $crypt->setKey( + substr($key, 0, 16) + ); + $encryption = $crypt->encrypt($test); - $actual = rtrim($crypt->decrypt($encryption), "\0"); + + $actual = rtrim( + $crypt->decrypt($encryption), + "\0" + ); + $I->assertEquals($test, $actual); } foreach ($tests as $key => $test) { - $encryption = $crypt->encrypt($test, substr($key, 0, 16)); - $actual = rtrim($crypt->decrypt($encryption, substr($key, 0, 16)), "\0"); + $encryption = $crypt->encrypt( + $test, + substr($key, 0, 16) + ); + + $actual = rtrim( + $crypt->decrypt( + $encryption, + substr($key, 0, 16) + ), + "\0" + ); + $I->assertEquals($test, $actual); } } diff --git a/tests/unit/Crypt/SetCipherCest.php b/tests/unit/Crypt/SetCipherCest.php index ffbf7068d85..1a8c33d5f9f 100644 --- a/tests/unit/Crypt/SetCipherCest.php +++ b/tests/unit/Crypt/SetCipherCest.php @@ -34,9 +34,15 @@ public function cryptSetCipher(UnitTester $I) $I->wantToTest('Crypt - setCipher()'); $cipher = "aes-256-cfb"; + $crypt = new Crypt(); + $crypt->setCipher($cipher); - $I->assertEquals($cipher, $crypt->getCipher()); + + $I->assertEquals( + $cipher, + $crypt->getCipher() + ); } /** @@ -55,6 +61,7 @@ public function shouldThrowExceptionIfCipherIsUnknown(UnitTester $I) Exception::class, function () { $crypt = new Crypt(); + $crypt->setCipher('xxx-yyy-zzz'); } ); diff --git a/tests/unit/Crypt/SetPaddingCest.php b/tests/unit/Crypt/SetPaddingCest.php index f9c8a309b83..ec713f9f43d 100644 --- a/tests/unit/Crypt/SetPaddingCest.php +++ b/tests/unit/Crypt/SetPaddingCest.php @@ -31,14 +31,20 @@ class SetPaddingCest public function cryptSetPadding(UnitTester $I) { $I->wantToTest('Crypt - setPadding()'); - $texts = ['']; - $key = '0123456789ABCDEF0123456789ABCDEF'; + + $texts = [ + '', + ]; + + $key = '0123456789ABCDEF0123456789ABCDEF'; + $ciphers = [ 'AES-256-ECB', 'AES-256-CBC', 'AES-256-CFB', ]; - $pads = [ + + $pads = [ Crypt::PADDING_ANSI_X_923, Crypt::PADDING_PKCS7, Crypt::PADDING_ISO_10126, @@ -52,7 +58,10 @@ public function cryptSetPadding(UnitTester $I) } $crypt = new Crypt(); - $crypt->setKey(substr($key, 0, 32)); + + $crypt->setKey( + substr($key, 0, 32) + ); foreach ($pads as $padding) { $crypt->setPadding($padding); @@ -63,6 +72,7 @@ public function cryptSetPadding(UnitTester $I) foreach ($texts as $expected) { $encrypted = $crypt->encrypt($expected); $actual = $crypt->decrypt($encrypted); + $I->assertEquals($expected, $actual); } } diff --git a/tests/unit/Events/ManagerCest.php b/tests/unit/Events/ManagerCest.php index ff4c73a7fb6..a6d0abb559e 100644 --- a/tests/unit/Events/ManagerCest.php +++ b/tests/unit/Events/ManagerCest.php @@ -11,6 +11,7 @@ namespace Phalcon\Test\Unit\Events; +use Codeception\Example; use ComponentX; use ComponentY; use Phalcon\Events\Event; @@ -49,21 +50,41 @@ public function attachingListenersByEventNameAfterDetachingAll(UnitTester $I) $component = new ComponentX(); $eventsManager = new Manager(); + $eventsManager->attach('log', $first); $component->setEventsManager($eventsManager); $logListeners = $component->getEventsManager()->getListeners('log'); - $I->assertCount(1, $logListeners); - $I->assertInstanceOf(FirstListener::class, $logListeners[0]); + $I->assertCount( + 1, + $logListeners + ); + + $I->assertInstanceOf( + FirstListener::class, + $logListeners[0] + ); $component->getEventsManager()->attach('log', $second); + $logListeners = $component->getEventsManager()->getListeners('log'); - $I->assertCount(2, $logListeners); - $I->assertInstanceOf(FirstListener::class, $logListeners[0]); - $I->assertInstanceOf(SecondListener::class, $logListeners[1]); + $I->assertCount( + 2, + $logListeners + ); + + $I->assertInstanceOf( + FirstListener::class, + $logListeners[0] + ); + + $I->assertInstanceOf( + SecondListener::class, + $logListeners[1] + ); $component->getEventsManager()->detachAll('log'); $logListeners = $component->getEventsManager()->getListeners('log'); @@ -73,8 +94,15 @@ public function attachingListenersByEventNameAfterDetachingAll(UnitTester $I) $component->getEventsManager()->attach('log', $second); $logListeners = $component->getEventsManager()->getListeners('log'); - $I->assertCount(1, $logListeners); - $I->assertInstanceOf(SecondListener::class, $logListeners[0]); + $I->assertCount( + 1, + $logListeners + ); + + $I->assertInstanceOf( + SecondListener::class, + $logListeners[0] + ); } /** @@ -209,6 +237,7 @@ public function stopEventsInEventsManager(UnitTester $I) $propagationListener = function (Event $event, $component, $data) use (&$number) { $number++; + $event->stop(); }; @@ -227,33 +256,42 @@ public function stopEventsInEventsManager(UnitTester $I) * @issue https://github.com/phalcon/cphalcon/issues/12882 * @author Phalcon Team * @since 2017-06-06 + * + * @dataProvider booleanProvider */ - public function detachClosureListener(UnitTester $I) + public function detachClosureListener(UnitTester $I, Example $example) { - $examples = [true, false]; - foreach ($examples as $enablePriorities) { - $manager = new Manager(); - $manager->enablePriorities($enablePriorities); + $enablePriorities = $example[0]; + + $manager = new Manager(); + $manager->enablePriorities($enablePriorities); - $handler = function () { - echo __METHOD__; - }; + $handler = function () { + echo __METHOD__; + }; + + $manager->attach('test:detachable', $handler); + $events = $I->getProtectedProperty($manager, 'events'); - $manager->attach('test:detachable', $handler); - $events = $I->getProtectedProperty($manager, 'events'); + $I->assertCount(1, $events); + $I->assertTrue(array_key_exists('test:detachable', $events)); + $I->assertCount(1, $events['test:detachable']); - $I->assertCount(1, $events); - $I->assertTrue(array_key_exists('test:detachable', $events)); - $I->assertCount(1, $events['test:detachable']); + $manager->detach('test:detachable', $handler); - $manager->detach('test:detachable', $handler); + $events = $I->getProtectedProperty($manager, 'events'); - $events = $I->getProtectedProperty($manager, 'events'); + $I->assertCount(1, $events); + $I->assertTrue(array_key_exists('test:detachable', $events)); + $I->assertCount(0, $events['test:detachable']); + } - $I->assertCount(1, $events); - $I->assertTrue(array_key_exists('test:detachable', $events)); - $I->assertCount(0, $events['test:detachable']); - } + private function booleanProvider(): array + { + return [ + [true], + [false], + ]; } /** @@ -263,30 +301,44 @@ public function detachClosureListener(UnitTester $I) * @issue https://github.com/phalcon/cphalcon/issues/12882 * @author Phalcon Team * @since 2017-06-06 + * + * @dataProvider booleanProvider */ - public function detachObjectListener(UnitTester $I) + public function detachObjectListener(UnitTester $I, Example $example) { - $examples = [true, false]; - foreach ($examples as $enablePriorities) { - $manager = new Manager(); - $manager->enablePriorities($enablePriorities); + $enablePriorities = $example[0]; + + + + $manager = new Manager(); + + $manager->enablePriorities($enablePriorities); + + $handler = new \stdClass(); + + $manager->attach('test:detachable', $handler); + + $events = $I->getProtectedProperty($manager, 'events'); + + $I->assertCount(1, $events); + + $I->assertTrue( + array_key_exists('test:detachable', $events) + ); + + $I->assertCount(1, $events['test:detachable']); - $handler = new \stdClass(); - $manager->attach('test:detachable', $handler); - $events = $I->getProtectedProperty($manager, 'events'); + $manager->detach('test:detachable', $handler); - $I->assertCount(1, $events); - $I->assertTrue(array_key_exists('test:detachable', $events)); - $I->assertCount(1, $events['test:detachable']); + $events = $I->getProtectedProperty($manager, 'events'); - $manager->detach('test:detachable', $handler); + $I->assertCount(1, $events); - $events = $I->getProtectedProperty($manager, 'events'); + $I->assertTrue( + array_key_exists('test:detachable', $events) + ); - $I->assertCount(1, $events); - $I->assertTrue(array_key_exists('test:detachable', $events)); - $I->assertCount(0, $events['test:detachable']); - } + $I->assertCount(0, $events['test:detachable']); } public function setLastListener($listener) diff --git a/tests/unit/Flash/Direct/Helper/FlashBase.php b/tests/unit/Flash/Direct/Helper/FlashBase.php index 20a4806e93e..06ce8bdda19 100644 --- a/tests/unit/Flash/Direct/Helper/FlashBase.php +++ b/tests/unit/Flash/Direct/Helper/FlashBase.php @@ -74,6 +74,7 @@ private function stringTest(UnitTester $I, $function) if ($this->notHtml) { $flash->setAutomaticHtml(false); + $expected = $message; } else { $expected = sprintf($template, $class, $message); @@ -82,6 +83,7 @@ private function stringTest(UnitTester $I, $function) if ($this->notImplicit) { $flash->setImplicitFlush(false); + $actual = $flash->$function($message); } else { $actual = $this->getObResponse($flash, $function, $message); @@ -157,7 +159,9 @@ public function testFlashDirectNoImplicitFlushHtml(UnitTester $I) foreach ($functions as $function) { $this->notImplicit = true; + $this->stringTest($I, $function); + $this->notImplicit = false; } } @@ -179,7 +183,9 @@ public function testFlashDirectImplicitFlushNoHtml(UnitTester $I) foreach ($functions as $function) { $this->notHtml = true; + $this->stringTest($I, $function); + $this->notHtml = false; } } @@ -202,7 +208,9 @@ public function testFlashDirectNoImplicitFlushNoHtml(UnitTester $I) foreach ($functions as $function) { $this->notHtml = true; $this->notImplicit = true; + $this->stringTest($I, $function); + $this->notHtml = false; $this->notImplicit = false; } diff --git a/tests/unit/Flash/SessionCest.php b/tests/unit/Flash/SessionCest.php index f12ef57d1fa..5f361dd3c5a 100644 --- a/tests/unit/Flash/SessionCest.php +++ b/tests/unit/Flash/SessionCest.php @@ -100,7 +100,9 @@ public function testShouldAutoEscapeHtml(UnitTester $I) protected function getFlash() { $container = $this->getDi(); - $flash = new Session($this->classes); + + $flash = new Session($this->classes); + $flash->setDI($container); return $flash; @@ -149,16 +151,20 @@ public function testGetNonExistentType(UnitTester $I) * @TODO Check the session */ $I->skipTest('TODO: Check the session'); + $flash = $this->getFlash(); + $flash->error('sample error'); - $expected = []; - $actual = $flash->getMessages('success', false); - $I->assertEquals($expected, $actual); + $I->assertEquals( + [], + $flash->getMessages('success', false) + ); - $expected = 1; - $actual = count($flash->getMessages()); - $I->assertTrue($expected === $actual); + $I->assertCount( + 1, + $flash->getMessages() + ); } /** @@ -173,6 +179,7 @@ public function testClearMessagesFormSession(UnitTester $I) * @TODO Check the session */ $I->skipTest('TODO: Check the session'); + $flash = $this->getFlash(); ob_start(); @@ -181,9 +188,11 @@ public function testClearMessagesFormSession(UnitTester $I) $flash->clear(); $actual = ob_get_contents(); ob_end_clean(); - $expected = ''; - $I->assertEquals($expected, $actual); + $I->assertEquals( + '', + $actual + ); } /** @@ -198,6 +207,7 @@ public function testMessageFormat(UnitTester $I) * @TODO Check the session */ $I->skipTest('TODO: Check the session'); + $examples = [ 'error', 'success', @@ -232,13 +242,16 @@ public function testMessageFormat(UnitTester $I) */ public function testCustomTemplateGetterSetter(UnitTester $I) { - $flash = $this->getFlash(); + $flash = $this->getFlash(); + $template = '%message%'; + $flash->setCustomTemplate($template); - $expected = $template; - $actual = $flash->getCustomTemplate(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $template, + $flash->getCustomTemplate() + ); } /** @@ -254,18 +267,24 @@ public function testCustomFormat(UnitTester $I) * @TODO Check the session */ $I->skipTest('TODO: Check the session'); + $flash = $this->getFlash(); $template = '%message%'; + $flash->setCustomTemplate($template); $message = 'sample message'; - $expected = 'sample message'; - ob_start(); + $flash->success($message); + + ob_start(); $flash->output(); $actual = ob_get_contents(); ob_end_clean(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 'sample message', + $actual + ); } } diff --git a/tests/unit/Helper/Str/RandomCest.php b/tests/unit/Helper/Str/RandomCest.php index 6303973aaed..f0cded45d2f 100644 --- a/tests/unit/Helper/Str/RandomCest.php +++ b/tests/unit/Helper/Str/RandomCest.php @@ -12,6 +12,7 @@ namespace Phalcon\Test\Unit\Helper\Str; +use Codeception\Example; use Phalcon\Helper\Str; use UnitTester; @@ -31,6 +32,7 @@ class RandomCest public function helperStrRandomConstants(UnitTester $I) { $I->wantToTest('Helper\Str - random() - constants'); + $I->assertEquals(0, Str::RANDOM_ALNUM); $I->assertEquals(1, Str::RANDOM_ALPHA); $I->assertEquals(2, Str::RANDOM_HEXDEC); @@ -50,20 +52,27 @@ public function helperStrRandomConstants(UnitTester $I) public function helperStrRandomAlnum(UnitTester $I) { $I->wantToTest('Helper\Str - random() - alnum'); + for ($i = 1; $i < 10; $i++) { - $source = Str::random(Str::RANDOM_ALNUM, $i); + $source = Str::random( + Str::RANDOM_ALNUM, + $i + ); - $expected = 1; - $actual = preg_match('/[a-zA-Z0-9]+/', $source, $matches); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + preg_match('/[a-zA-Z0-9]+/', $source, $matches) + ); - $expected = $source; - $actual = $matches[0]; - $I->assertEquals($expected, $actual); + $I->assertEquals( + $source, + $matches[0] + ); - $expected = $i; - $actual = strlen($source); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $i, + strlen($source) + ); } } @@ -78,20 +87,27 @@ public function helperStrRandomAlnum(UnitTester $I) public function helperStrRandomAlpha(UnitTester $I) { $I->wantToTest('Helper\Str - random() - alpha'); + for ($i = 1; $i < 10; $i++) { - $source = Str::random(Str::RANDOM_ALPHA, $i); + $source = Str::random( + Str::RANDOM_ALPHA, + $i + ); - $expected = 1; - $actual = preg_match('/[a-zA-Z]+/', $source, $matches); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + preg_match('/[a-zA-Z]+/', $source, $matches) + ); - $expected = $source; - $actual = $matches[0]; - $I->assertEquals($expected, $actual); + $I->assertEquals( + $source, + $matches[0] + ); - $expected = $i; - $actual = strlen($source); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $i, + strlen($source) + ); } } @@ -106,20 +122,27 @@ public function helperStrRandomAlpha(UnitTester $I) public function helperStrRandomHexDec(UnitTester $I) { $I->wantToTest('Helper\Str - random() - hexdex'); + for ($i = 1; $i < 10; $i++) { - $source = Str::random(Str::RANDOM_HEXDEC, $i); + $source = Str::random( + Str::RANDOM_HEXDEC, + $i + ); - $expected = 1; - $actual = preg_match('/[a-f0-9]+/', $source, $matches); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + preg_match('/[a-f0-9]+/', $source, $matches) + ); - $expected = $source; - $actual = $matches[0]; - $I->assertEquals($expected, $actual); + $I->assertEquals( + $source, + $matches[0] + ); - $expected = $i; - $actual = strlen($source); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $i, + strlen($source) + ); } } @@ -134,20 +157,27 @@ public function helperStrRandomHexDec(UnitTester $I) public function helperStrRandomNumeric(UnitTester $I) { $I->wantToTest('Helper\Str - random() - numeric'); + for ($i = 1; $i < 10; $i++) { - $source = Str::random(Str::RANDOM_NUMERIC, $i); + $source = Str::random( + Str::RANDOM_NUMERIC, + $i + ); - $expected = 1; - $actual = preg_match('/[0-9]+/', $source, $matches); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + preg_match('/[0-9]+/', $source, $matches) + ); - $expected = $source; - $actual = $matches[0]; - $I->assertEquals($expected, $actual); + $I->assertEquals( + $source, + $matches[0] + ); - $expected = $i; - $actual = strlen($source); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $i, + strlen($source) + ); } } @@ -162,20 +192,27 @@ public function helperStrRandomNumeric(UnitTester $I) public function helperStrRandomNonZero(UnitTester $I) { $I->wantToTest('Helper\Str - random() - non zero'); + for ($i = 1; $i < 10; $i++) { - $source = Str::random(Str::RANDOM_NOZERO, $i); + $source = Str::random( + Str::RANDOM_NOZERO, + $i + ); - $expected = 1; - $actual = preg_match('/[1-9]+/', $source, $matches); - $I->assertEquals($expected, $actual); + $I->assertEquals( + 1, + preg_match('/[1-9]+/', $source, $matches) + ); - $expected = $source; - $actual = $matches[0]; - $I->assertEquals($expected, $actual); + $I->assertEquals( + $source, + $matches[0] + ); - $expected = $i; - $actual = strlen($source); - $I->assertEquals($expected, $actual); + $I->assertEquals( + $i, + strlen($source) + ); } } @@ -186,22 +223,44 @@ public function helperStrRandomNonZero(UnitTester $I) * * @author Phalcon Team * @since 2019-04-06 + * + * @dataProvider helperStrRandomDistinctProvider */ - public function helperStrRandomDistinct(UnitTester $I) + public function helperStrRandomDistinct(UnitTester $I, Example $example) { $I->wantToTest('Helper\Str - random() - distinct'); - $examples = [1, 10, 100, 200, 500, 1000, 2000, 3000, 4000, 5000]; - foreach ($examples as $i) { - $source = Str::random(Str::RANDOM_DISTINCT, $i); - $pattern = '#^[^2345679ACDEFHJKLMNPRSTUVWXYZ]+$#'; - - $expected = 0; - $actual = preg_match($pattern, $source); - $I->assertEquals($expected, $actual); - - $expected = $i; - $actual = strlen($source); - $I->assertEquals($expected, $actual); - } + + $source = Str::random( + Str::RANDOM_DISTINCT, + $example[0] + ); + + $pattern = '#^[^2345679ACDEFHJKLMNPRSTUVWXYZ]+$#'; + + $I->assertEquals( + 0, + preg_match($pattern, $source) + ); + + $I->assertEquals( + $example[0], + strlen($source) + ); + } + + private function helperStrRandomDistinctProvider(): array + { + return [ + [1], + [10], + [100], + [200], + [500], + [1000], + [2000], + [3000], + [4000], + [5000], + ]; } } diff --git a/tests/unit/Html/Breadcrumbs/AddCest.php b/tests/unit/Html/Breadcrumbs/AddCest.php index ccf1157c341..691b257c445 100644 --- a/tests/unit/Html/Breadcrumbs/AddCest.php +++ b/tests/unit/Html/Breadcrumbs/AddCest.php @@ -31,14 +31,16 @@ class AddCest public function htmlBreadcrumbsAdd(UnitTester $I) { $I->wantToTest('Html\Breadcrumbs - add()'); + $breadcrumbs = new Breadcrumbs(); - $breadcrumbs - ->add('Home', '/'); - $expected = [ - '/' => 'Home', - ]; - $actual = $breadcrumbs->toArray(); - $I->assertEquals($expected, $actual); + $breadcrumbs->add('Home', '/'); + + $I->assertEquals( + [ + '/' => 'Home', + ], + $breadcrumbs->toArray() + ); } } diff --git a/tests/unit/Html/Breadcrumbs/ClearCest.php b/tests/unit/Html/Breadcrumbs/ClearCest.php index a5c8fd3bd54..5c98137f8b5 100644 --- a/tests/unit/Html/Breadcrumbs/ClearCest.php +++ b/tests/unit/Html/Breadcrumbs/ClearCest.php @@ -31,24 +31,29 @@ class ClearCest public function htmlBreadcrumbsClear(UnitTester $I) { $I->wantToTest('Html\Breadcrumbs - clear()'); + $breadcrumbs = new Breadcrumbs(); + $breadcrumbs ->add('Home', '/') ->add('Users', '/users') ->add('Phalcon Team') ; - $expected = [ - '/' => 'Home', - '/users' => 'Users', - '' => 'Phalcon Team', - ]; - $actual = $breadcrumbs->toArray(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + [ + '/' => 'Home', + '/users' => 'Users', + '' => 'Phalcon Team', + ], + $breadcrumbs->toArray() + ); $breadcrumbs->clear(); - $expected = []; - $actual = $breadcrumbs->toArray(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + [], + $breadcrumbs->toArray() + ); } } diff --git a/tests/unit/Html/Breadcrumbs/GetSetSeparatorCest.php b/tests/unit/Html/Breadcrumbs/GetSetSeparatorCest.php index c5eb27c8437..623184708d3 100644 --- a/tests/unit/Html/Breadcrumbs/GetSetSeparatorCest.php +++ b/tests/unit/Html/Breadcrumbs/GetSetSeparatorCest.php @@ -31,11 +31,16 @@ class GetSetSeparatorCest public function htmlBreadcrumbsGetSetSeparator(UnitTester $I) { $I->wantToTest('Html\Breadcrumbs - getSeparator()/setSeparator()'); + $breadcrumbs = new Breadcrumbs(); $expected = ' -:- '; + $breadcrumbs->setSeparator($expected); - $actual = $breadcrumbs->getSeparator(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $expected, + $breadcrumbs->getSeparator() + ); } } diff --git a/tests/unit/Html/Breadcrumbs/RemoveCest.php b/tests/unit/Html/Breadcrumbs/RemoveCest.php index 2ee60a04459..2e575d11072 100644 --- a/tests/unit/Html/Breadcrumbs/RemoveCest.php +++ b/tests/unit/Html/Breadcrumbs/RemoveCest.php @@ -31,27 +31,32 @@ class RemoveCest public function htmlBreadcrumbsRemove(UnitTester $I) { $I->wantToTest('Html\Breadcrumbs - remove()'); + $breadcrumbs = new Breadcrumbs(); + $breadcrumbs ->add('Home', '/') ->add('Users', '/users') ->add('Phalcon Team') ; - $expected = [ - '/' => 'Home', - '/users' => 'Users', - '' => 'Phalcon Team', - ]; - $actual = $breadcrumbs->toArray(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + [ + '/' => 'Home', + '/users' => 'Users', + '' => 'Phalcon Team', + ], + $breadcrumbs->toArray() + ); $breadcrumbs->remove('/'); - $expected = [ - '/users' => 'Users', - '' => 'Phalcon Team', - ]; - $actual = $breadcrumbs->toArray(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + [ + '/users' => 'Users', + '' => 'Phalcon Team', + ], + $breadcrumbs->toArray() + ); } } diff --git a/tests/unit/Html/Breadcrumbs/RenderCest.php b/tests/unit/Html/Breadcrumbs/RenderCest.php index 0ee46393ab8..dcb979252da 100644 --- a/tests/unit/Html/Breadcrumbs/RenderCest.php +++ b/tests/unit/Html/Breadcrumbs/RenderCest.php @@ -31,7 +31,9 @@ class RenderCest public function htmlBreadcrumbsRender(UnitTester $I) { $I->wantToTest('Html\Breadcrumbs - render()'); + $breadcrumbs = new Breadcrumbs(); + $breadcrumbs ->add('Home', '/') ->add('Phalcon Team') @@ -42,7 +44,10 @@ public function htmlBreadcrumbsRender(UnitTester $I) . '
/
' . '
Phalcon Team
' . ''; - $actual = $breadcrumbs->render(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $expected, + $breadcrumbs->render() + ); } } diff --git a/tests/unit/Html/Breadcrumbs/ToArrayCest.php b/tests/unit/Html/Breadcrumbs/ToArrayCest.php index aa57974f809..e567b3c6142 100644 --- a/tests/unit/Html/Breadcrumbs/ToArrayCest.php +++ b/tests/unit/Html/Breadcrumbs/ToArrayCest.php @@ -31,7 +31,9 @@ class ToArrayCest public function htmlBreadcrumbsToArray(UnitTester $I) { $I->wantToTest('Html\Breadcrumbs - toArray()'); + $breadcrumbs = new Breadcrumbs(); + $breadcrumbs ->add('Home', '/') ->add('Users', '/users') @@ -43,7 +45,10 @@ public function htmlBreadcrumbsToArray(UnitTester $I) '/users' => 'Users', '' => 'Phalcon Team', ]; - $actual = $breadcrumbs->toArray(); - $I->assertEquals($expected, $actual); + + $I->assertEquals( + $expected, + $breadcrumbs->toArray() + ); } } diff --git a/tests/unit/Html/Helper/AnchorCest.php b/tests/unit/Html/Helper/AnchorCest.php index c71874194d5..153cdc8f201 100644 --- a/tests/unit/Html/Helper/AnchorCest.php +++ b/tests/unit/Html/Helper/AnchorCest.php @@ -38,11 +38,14 @@ class AnchorCest public function htmlHelperAnchorConstruct(UnitTester $I, Example $example) { $I->wantToTest('Html\Helper\Anchor - __construct()'); + $escaper = $this->newEscaper(); + $anchor = new Anchor($escaper); $expected = $example[0]; $actual = $anchor('/myurl', 'click me', $example[1]); + $I->assertEquals($expected, $actual); } diff --git a/tests/unit/Html/Helper/ButtonCest.php b/tests/unit/Html/Helper/ButtonCest.php index 64732d62c11..9185401f0d9 100644 --- a/tests/unit/Html/Helper/ButtonCest.php +++ b/tests/unit/Html/Helper/ButtonCest.php @@ -38,11 +38,14 @@ class ButtonCest public function htmlHelperTextareaConstruct(UnitTester $I, Example $example) { $I->wantToTest('Html\Helper\Button - __construct()'); + $escaper = $this->newEscaper(); + $helper = new Button($escaper); $expected = $example[0]; $actual = $helper($example[1], $example[2]); + $I->assertEquals($expected, $actual); } diff --git a/tests/unit/Html/Helper/ElementCest.php b/tests/unit/Html/Helper/ElementCest.php index 745ec4c2b29..0d04c2d3dac 100644 --- a/tests/unit/Html/Helper/ElementCest.php +++ b/tests/unit/Html/Helper/ElementCest.php @@ -38,7 +38,9 @@ class ElementCest public function htmlHelperElementConstruct(UnitTester $I, Example $example) { $I->wantToTest('Html\Helper\Element - __construct()'); + $escaper = $this->newEscaper(); + $helper = new Element($escaper); $expected = $example[0]; diff --git a/tests/unit/Html/Helper/FormCest.php b/tests/unit/Html/Helper/FormCest.php index ba813fd9d3b..757e73bf2a3 100644 --- a/tests/unit/Html/Helper/FormCest.php +++ b/tests/unit/Html/Helper/FormCest.php @@ -38,11 +38,14 @@ class FormCest public function htmlHelperFormConstruct(UnitTester $I, Example $example) { $I->wantToTest('Html\Helper\Form - __construct()'); + $escaper = $this->newEscaper(); + $helper = new Form($escaper); $expected = $example[0]; $actual = $helper($example[1]); + $I->assertEquals($expected, $actual); } diff --git a/tests/unit/Html/Helper/FormCloseCest.php b/tests/unit/Html/Helper/FormCloseCest.php index 548a7a96c49..3f5890fa803 100644 --- a/tests/unit/Html/Helper/FormCloseCest.php +++ b/tests/unit/Html/Helper/FormCloseCest.php @@ -34,11 +34,14 @@ class FormCloseCest public function htmlHelperFormcloseConstruct(UnitTester $I) { $I->wantToTest('Html\Helper\FormClose - __construct()'); + $escaper = $this->newEscaper(); + $helper = new FormClose($escaper); - $expected = ''; - $actual = $helper(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + '', + $helper() + ); } } diff --git a/tests/unit/Html/Helper/TextAreaCest.php b/tests/unit/Html/Helper/TextAreaCest.php index 59703b38d2d..42d4551e89a 100644 --- a/tests/unit/Html/Helper/TextAreaCest.php +++ b/tests/unit/Html/Helper/TextAreaCest.php @@ -38,11 +38,14 @@ class TextAreaCest public function htmlHelperTextareaConstruct(UnitTester $I, Example $example) { $I->wantToTest('Html\Helper\TextArea - __construct()'); + $escaper = $this->newEscaper(); + $helper = new TextArea($escaper); $expected = $example[0]; $actual = $helper($example[1], $example[2]); + $I->assertEquals($expected, $actual); } diff --git a/tests/unit/Html/Tag/AppendTitleCest.php b/tests/unit/Html/Tag/AppendTitleCest.php index 77418bbd9a9..59df83a7ae4 100644 --- a/tests/unit/Html/Tag/AppendTitleCest.php +++ b/tests/unit/Html/Tag/AppendTitleCest.php @@ -38,24 +38,30 @@ class AppendTitleCest public function htmlTagAppendTitle(UnitTester $I) { $I->wantToTest('Html\Tag - appendTitle()'); + $tag = new Tag(); + $tag->setDI($this->container); + $tag ->setTitle('Title') ->appendTitle(['Class']) ; - $expected = "Title"; - $actual = $tag->getTitle(false, false); - $I->assertEquals($expected, $actual); + $I->assertEquals( + "Title", + $tag->getTitle(false, false) + ); - $expected = "TitleClass"; - $actual = $tag->getTitle(false, true); - $I->assertEquals($expected, $actual); + $I->assertEquals( + "TitleClass", + $tag->getTitle(false, true) + ); - $expected = "TitleClass" . PHP_EOL; - $actual = $tag->renderTitle(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + "TitleClass" . PHP_EOL, + $tag->renderTitle() + ); } /** @@ -69,25 +75,31 @@ public function htmlTagAppendTitle(UnitTester $I) public function htmlTagAppendTitleSeparator(UnitTester $I) { $I->wantToTest('Html\Tag - appendTitle() - separator'); + $tag = new Tag(); + $tag->setDI($this->container); + $tag ->setTitle('Title') ->setTitleSeparator('|') ->appendTitle(['Class']) ; - $expected = "Title"; - $actual = $tag->getTitle(false, false); - $I->assertEquals($expected, $actual); + $I->assertEquals( + "Title", + $tag->getTitle(false, false) + ); - $expected = "Title|Class"; - $actual = $tag->getTitle(false, true); - $I->assertEquals($expected, $actual); + $I->assertEquals( + "Title|Class", + $tag->getTitle(false, true) + ); - $expected = "Title|Class" . PHP_EOL; - $actual = $tag->renderTitle(); - $I->assertEquals($expected, $actual); + $I->assertEquals( + "Title|Class" . PHP_EOL, + $tag->renderTitle() + ); } /** diff --git a/tests/unit/Html/Tag/ClearCest.php b/tests/unit/Html/Tag/ClearCest.php index 5bad4d05a90..400396a5e79 100644 --- a/tests/unit/Html/Tag/ClearCest.php +++ b/tests/unit/Html/Tag/ClearCest.php @@ -33,15 +33,19 @@ class ClearCest public function htmlTagClear(UnitTester $I) { $I->wantToTest('Html\Tag - clear()'); + $tag = new Tag(); $tag->setAttribute('name', 'Phalcon'); - $actual = $tag->hasValue('name'); - $I->assertTrue($actual); + + $I->assertTrue( + $tag->hasValue('name') + ); $tag->clear(); - $actual = $tag->hasValue('name'); - $I->assertFalse($actual); + $I->assertFalse( + $tag->hasValue('name') + ); } } diff --git a/tests/unit/Html/Tag/ConstantsCest.php b/tests/unit/Html/Tag/ConstantsCest.php index 698e30f0dad..d4d9c1e9b28 100644 --- a/tests/unit/Html/Tag/ConstantsCest.php +++ b/tests/unit/Html/Tag/ConstantsCest.php @@ -33,6 +33,7 @@ class ConstantsCest public function htmlTagConstants(UnitTester $I) { $I->wantToTest('Html\Tag - constants()'); + $I->assertEquals(1, Tag::HTML32); $I->assertEquals(2, Tag::HTML401_STRICT); $I->assertEquals(3, Tag::HTML401_TRANSITIONAL); diff --git a/tests/unit/Html/Tag/ElementCest.php b/tests/unit/Html/Tag/ElementCest.php index 9e49765813f..6fc9354e6ca 100644 --- a/tests/unit/Html/Tag/ElementCest.php +++ b/tests/unit/Html/Tag/ElementCest.php @@ -167,26 +167,38 @@ public function htmlTagElementOnlyStart(UnitTester $I) public function htmlTagElementEol(UnitTester $I) { $I->wantToTest("Tag - tagHtml() - name parameter EOL"); + $tag = new Tag(); + $tag->setDI($this->container); - $name = 'aside'; + + $name = 'aside'; + $parameters = [ 'useEol' => true, ]; - $expected = '