diff --git a/composer.json b/composer.json index fb25e4f9..53ff0e05 100644 --- a/composer.json +++ b/composer.json @@ -67,7 +67,7 @@ "phpstan/phpstan-doctrine": "^0.11.4", "phpstan/phpstan-phpunit": "^0.11.2", "phpstan/phpstan-symfony": "^0.11.6", - "phpunit/phpunit": "^7.0", + "phpunit/phpunit": "^8.0", "symfony/browser-kit": "^4.0", "symfony/css-selector": "^4.0", "symfony/maker-bundle": "^1.12", diff --git a/composer.lock b/composer.lock index 8fefa2fb..2a70564e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7aa966dd59dc7f6c13c113695ed0b56b", + "content-hash": "7936bc91f5917f2a6416fcdcc049ae7e", "packages": [ { "name": "beberlei/doctrineextensions", @@ -3788,16 +3788,16 @@ }, { "name": "nesbot/carbon", - "version": "2.24.0", + "version": "2.25.0", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "934459c5ac0658bc765ad1e53512c7c77adcac29" + "reference": "b70da677101cca7b584c7489770d2677c2733593" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/934459c5ac0658bc765ad1e53512c7c77adcac29", - "reference": "934459c5ac0658bc765ad1e53512c7c77adcac29", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/b70da677101cca7b584c7489770d2677c2733593", + "reference": "b70da677101cca7b584c7489770d2677c2733593", "shasum": "" }, "require": { @@ -3844,14 +3844,14 @@ "homepage": "http://github.com/kylekatarnls" } ], - "description": "A API extension for DateTime that supports 281 different languages.", + "description": "An API extension for DateTime that supports 281 different languages.", "homepage": "http://carbon.nesbot.com", "keywords": [ "date", "datetime", "time" ], - "time": "2019-08-31T16:37:55+00:00" + "time": "2019-09-30T16:22:22+00:00" }, { "name": "ocramius/package-versions", @@ -10488,22 +10488,22 @@ }, { "name": "phpspec/prophecy", - "version": "1.8.1", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76" + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76", - "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/f6811d96d97bdf400077a0cc100ae56aa32b9203", + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0", "sebastian/comparator": "^1.1|^2.0|^3.0", "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, @@ -10547,7 +10547,7 @@ "spy", "stub" ], - "time": "2019-06-13T12:50:23+00:00" + "time": "2019-10-03T11:07:50+00:00" }, { "name": "phpstan/phpdoc-parser", @@ -10862,40 +10862,40 @@ }, { "name": "phpunit/php-code-coverage", - "version": "6.1.4", + "version": "7.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d" + "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", - "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa0d179a13284c7420fc281fc32750e6cc7c9e2f", + "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", - "php": "^7.1", - "phpunit/php-file-iterator": "^2.0", + "php": "^7.2", + "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.0", + "phpunit/php-token-stream": "^3.1.1", "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^3.1 || ^4.0", + "sebastian/environment": "^4.2.2", "sebastian/version": "^2.0.1", - "theseer/tokenizer": "^1.1" + "theseer/tokenizer": "^1.1.3" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^8.2.2" }, "suggest": { - "ext-xdebug": "^2.6.0" + "ext-xdebug": "^2.7.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "6.1-dev" + "dev-master": "7.0-dev" } }, "autoload": { @@ -10921,7 +10921,7 @@ "testing", "xunit" ], - "time": "2018-10-31T16:06:48+00:00" + "time": "2019-09-17T06:24:36+00:00" }, { "name": "phpunit/php-file-iterator", @@ -11114,53 +11114,52 @@ }, { "name": "phpunit/phpunit", - "version": "7.5.16", + "version": "8.3.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "316afa6888d2562e04aeb67ea7f2017a0eb41661" + "reference": "302faed7059fde575cf3403a78c730c5e3a62750" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/316afa6888d2562e04aeb67ea7f2017a0eb41661", - "reference": "316afa6888d2562e04aeb67ea7f2017a0eb41661", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/302faed7059fde575cf3403a78c730c5e3a62750", + "reference": "302faed7059fde575cf3403a78c730c5e3a62750", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.1", + "doctrine/instantiator": "^1.2.0", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", - "myclabs/deep-copy": "^1.7", - "phar-io/manifest": "^1.0.2", - "phar-io/version": "^2.0", - "php": "^7.1", - "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^6.0.7", - "phpunit/php-file-iterator": "^2.0.1", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.9.1", + "phar-io/manifest": "^1.0.3", + "phar-io/version": "^2.0.1", + "php": "^7.2", + "phpspec/prophecy": "^1.8.1", + "phpunit/php-code-coverage": "^7.0.7", + "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-timer": "^2.1", - "sebastian/comparator": "^3.0", - "sebastian/diff": "^3.0", - "sebastian/environment": "^4.0", - "sebastian/exporter": "^3.1", - "sebastian/global-state": "^2.0", + "phpunit/php-timer": "^2.1.2", + "sebastian/comparator": "^3.0.2", + "sebastian/diff": "^3.0.2", + "sebastian/environment": "^4.2.2", + "sebastian/exporter": "^3.1.1", + "sebastian/global-state": "^3.0.0", "sebastian/object-enumerator": "^3.0.3", - "sebastian/resource-operations": "^2.0", + "sebastian/resource-operations": "^2.0.1", + "sebastian/type": "^1.1.3", "sebastian/version": "^2.0.1" }, - "conflict": { - "phpunit/phpunit-mock-objects": "*" - }, "require-dev": { "ext-pdo": "*" }, "suggest": { "ext-soap": "*", "ext-xdebug": "*", - "phpunit/php-invoker": "^2.0" + "phpunit/php-invoker": "^2.0.0" }, "bin": [ "phpunit" @@ -11168,7 +11167,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "7.5-dev" + "dev-master": "8.3-dev" } }, "autoload": { @@ -11194,7 +11193,7 @@ "testing", "xunit" ], - "time": "2019-09-14T09:08:39+00:00" + "time": "2019-09-14T09:12:03+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -11483,23 +11482,26 @@ }, { "name": "sebastian/global-state", - "version": "2.0.0", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" + "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", - "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", + "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", "shasum": "" }, "require": { - "php": "^7.0" + "php": "^7.2", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "ext-dom": "*", + "phpunit/phpunit": "^8.0" }, "suggest": { "ext-uopz": "*" @@ -11507,7 +11509,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -11530,7 +11532,7 @@ "keywords": [ "global state" ], - "time": "2017-04-27T15:39:26+00:00" + "time": "2019-02-01T05:30:01+00:00" }, { "name": "sebastian/object-enumerator", @@ -11719,6 +11721,52 @@ "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "time": "2018-10-04T04:07:39+00:00" }, + { + "name": "sebastian/type", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/3aaaa15fa71d27650d62a948be022fe3b48541a3", + "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3", + "shasum": "" + }, + "require": { + "php": "^7.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "time": "2019-07-02T08:10:15+00:00" + }, { "name": "sebastian/version", "version": "2.0.1", diff --git a/src/API/ActivityController.php b/src/API/ActivityController.php index b5b2d749..badf15ba 100644 --- a/src/API/ActivityController.php +++ b/src/API/ActivityController.php @@ -138,7 +138,6 @@ class ActivityController extends BaseApiController */ public function getAction($id) { - /** @var Activity $data */ $data = $this->repository->find($id); if (null === $data) { diff --git a/src/API/CustomerController.php b/src/API/CustomerController.php index 423cd09a..62821d65 100644 --- a/src/API/CustomerController.php +++ b/src/API/CustomerController.php @@ -117,7 +117,6 @@ class CustomerController extends BaseApiController */ public function getAction($id) { - /** @var Customer $data */ $data = $this->repository->find($id); if (null === $data) { diff --git a/src/API/ProjectController.php b/src/API/ProjectController.php index eb7f9402..34ed6ac7 100644 --- a/src/API/ProjectController.php +++ b/src/API/ProjectController.php @@ -122,7 +122,6 @@ class ProjectController extends BaseApiController */ public function getAction($id) { - /** @var Project $data */ $data = $this->repository->find($id); if (null === $data) { diff --git a/src/API/TeamController.php b/src/API/TeamController.php index cb0d23a9..48738efb 100644 --- a/src/API/TeamController.php +++ b/src/API/TeamController.php @@ -81,7 +81,6 @@ class TeamController extends BaseApiController */ public function getAction($id) { - /** @var Team $data */ $data = $this->repository->find($id); if (null === $data) { diff --git a/src/API/TimesheetController.php b/src/API/TimesheetController.php index 0e88d3d3..0acb4881 100644 --- a/src/API/TimesheetController.php +++ b/src/API/TimesheetController.php @@ -247,7 +247,6 @@ class TimesheetController extends BaseApiController */ public function getAction($id) { - /** @var Timesheet $data */ $data = $this->repository->find($id); if (null === $data) { @@ -545,7 +544,6 @@ class TimesheetController extends BaseApiController */ public function stopAction($id) { - /** @var Timesheet $timesheet */ $timesheet = $this->repository->find($id); if (null === $timesheet) { @@ -590,7 +588,6 @@ class TimesheetController extends BaseApiController */ public function restartAction($id, ParamFetcherInterface $paramFetcher, ValidatorInterface $validator) { - /** @var Timesheet $timesheet */ $timesheet = $this->repository->find($id); if (null === $timesheet) { @@ -678,7 +675,6 @@ class TimesheetController extends BaseApiController */ public function exportAction($id) { - /** @var Timesheet $timesheet */ $timesheet = $this->repository->find($id); if (null === $timesheet) { diff --git a/src/DataFixtures/CustomerFixtures.php b/src/DataFixtures/CustomerFixtures.php index 022342a4..f8e6c083 100644 --- a/src/DataFixtures/CustomerFixtures.php +++ b/src/DataFixtures/CustomerFixtures.php @@ -40,7 +40,6 @@ class CustomerFixtures extends Fixture public const MAX_PROJECTS_PER_CUSTOMER = 25; public const MIN_ACTIVITIES_PER_PROJECT = 0; public const MAX_ACTIVITIES_PER_PROJECT = 25; - public const INDICATE_HIDDEN = false; /** * @param ObjectManager $manager @@ -94,7 +93,7 @@ class CustomerFixtures extends Fixture $entry = new Customer(); $entry ->setCurrency($faker->currencyCode) - ->setName($faker->company . (self::INDICATE_HIDDEN && !$visible ? ' (x)' : '')) + ->setName($faker->company) ->setAddress($faker->address) ->setComment($faker->text) ->setNumber('C-' . $faker->ean8) @@ -125,7 +124,7 @@ class CustomerFixtures extends Fixture $entry = new Project(); $entry - ->setName($faker->catchPhrase . (self::INDICATE_HIDDEN && !$visible ? ' (x)' : '')) + ->setName($faker->catchPhrase) ->setComment($faker->text) ->setCustomer($customer) ->setOrderNumber('P-' . $faker->ean8) @@ -153,7 +152,7 @@ class CustomerFixtures extends Fixture { $entry = new Activity(); $entry - ->setName($faker->bs . (self::INDICATE_HIDDEN && !$visible ? ' (x)' : '')) + ->setName($faker->bs) ->setProject($project) ->setComment($faker->text) ->setVisible($visible) diff --git a/src/DependencyInjection/Compiler/DoctrineCompilerPass.php b/src/DependencyInjection/Compiler/DoctrineCompilerPass.php index 79ba6abc..ae00e189 100644 --- a/src/DependencyInjection/Compiler/DoctrineCompilerPass.php +++ b/src/DependencyInjection/Compiler/DoctrineCompilerPass.php @@ -43,7 +43,7 @@ class DoctrineCompilerPass implements CompilerPassInterface $engine = getenv('DATABASE_ENGINE'); } - if (null === $engine) { + if (false === $engine) { throw new \Exception( 'Could not detect database engine. Please set the environment config DATABASE_ENGINE ' . 'to one of: "' . implode(', ', $this->allowedEngines) . '" in your .env file, e.g. DATABASE_ENGINE=sqlite' diff --git a/src/Doctrine/UTCDateTimeType.php b/src/Doctrine/UTCDateTimeType.php index d85d1e3f..b1d74387 100644 --- a/src/Doctrine/UTCDateTimeType.php +++ b/src/Doctrine/UTCDateTimeType.php @@ -16,7 +16,7 @@ use Doctrine\DBAL\Types\DateTimeType; class UTCDateTimeType extends DateTimeType { /** - * @var \DateTimeZone + * @var \DateTimeZone|null */ private static $utc; diff --git a/src/Event/PrepareUserEvent.php b/src/Event/PrepareUserEvent.php index 40245b82..23bbcd0e 100644 --- a/src/Event/PrepareUserEvent.php +++ b/src/Event/PrepareUserEvent.php @@ -21,24 +21,17 @@ final class PrepareUserEvent extends Event * @deprecated since 1.4, will be removed with 2.0 */ public const PREPARE = PrepareUserEvent::class; - /** * @var User */ - protected $user; + private $user; - /** - * @param User $user - */ public function __construct(User $user) { $this->user = $user; } - /** - * @return User - */ - public function getUser() + public function getUser(): User { return $this->user; } diff --git a/src/EventSubscriber/TimezoneSubscriber.php b/src/EventSubscriber/TimezoneSubscriber.php index a00e83de..ce724bdb 100644 --- a/src/EventSubscriber/TimezoneSubscriber.php +++ b/src/EventSubscriber/TimezoneSubscriber.php @@ -52,7 +52,6 @@ class TimezoneSubscriber implements EventSubscriberInterface return false; } - /* @var $user User */ $user = $this->storage->getToken()->getUser(); if (null === $user) { diff --git a/src/EventSubscriber/UserPreferenceSubscriber.php b/src/EventSubscriber/UserPreferenceSubscriber.php index 33a31d4a..258ea1a5 100644 --- a/src/EventSubscriber/UserPreferenceSubscriber.php +++ b/src/EventSubscriber/UserPreferenceSubscriber.php @@ -151,10 +151,6 @@ class UserPreferenceSubscriber implements EventSubscriberInterface */ public function loadUserPreferences(PrepareUserEvent $event) { - if (!$this->canHandleEvent($event)) { - return; - } - $user = $event->getUser(); $prefs = []; @@ -182,17 +178,4 @@ class UserPreferenceSubscriber implements EventSubscriberInterface $user->setPreferences(array_values($prefs)); } - - /** - * @param PrepareUserEvent $event - * @return bool - */ - protected function canHandleEvent(PrepareUserEvent $event): bool - { - if (null === ($user = $event->getUser())) { - return false; - } - - return ($user instanceof User); - } } diff --git a/src/Form/DataTransformer/DurationStringToSecondsTransformer.php b/src/Form/DataTransformer/DurationStringToSecondsTransformer.php index 5ebb0968..bbdd79a8 100644 --- a/src/Form/DataTransformer/DurationStringToSecondsTransformer.php +++ b/src/Form/DataTransformer/DurationStringToSecondsTransformer.php @@ -46,7 +46,7 @@ class DurationStringToSecondsTransformer implements DataTransformerInterface } /** - * @param string $formatToInt + * @param string|null $formatToInt * @return int|null */ public function reverseTransform($formatToInt) diff --git a/src/Form/Model/DateRange.php b/src/Form/Model/DateRange.php index 33c80fb9..10a252ed 100644 --- a/src/Form/Model/DateRange.php +++ b/src/Form/Model/DateRange.php @@ -11,49 +11,35 @@ namespace App\Form\Model; use DateTime; -class DateRange +final class DateRange { /** * @var DateTime */ - protected $begin; + private $begin; /** * @var DateTime */ - protected $end; + private $end; - /** - * @return DateTime - */ public function getBegin(): ?DateTime { return $this->begin; } - /** - * @param DateTime $begin - * @return DateRange - */ - public function setBegin(DateTime $begin) + public function setBegin(DateTime $begin): DateRange { $this->begin = $begin; return $this; } - /** - * @return DateTime - */ public function getEnd(): ?DateTime { return $this->end; } - /** - * @param DateTime $end - * @return DateRange - */ - public function setEnd(DateTime $end) + public function setEnd(DateTime $end): DateRange { $this->end = $end; diff --git a/src/Form/TimesheetEditForm.php b/src/Form/TimesheetEditForm.php index 284d8829..bb9edaf7 100644 --- a/src/Form/TimesheetEditForm.php +++ b/src/Form/TimesheetEditForm.php @@ -295,7 +295,7 @@ class TimesheetEditForm extends AbstractType $builder->addEventListener( FormEvents::POST_SET_DATA, function (FormEvent $event) { - /** @var Timesheet $data */ + /** @var Timesheet|null $data */ $data = $event->getData(); if (null === $data || null === $data->getEnd()) { $event->getForm()->get('duration')->setData(null); diff --git a/src/Invoice/Calculator/AbstractCalculator.php b/src/Invoice/Calculator/AbstractCalculator.php index fabb38d1..a8ee3a51 100644 --- a/src/Invoice/Calculator/AbstractCalculator.php +++ b/src/Invoice/Calculator/AbstractCalculator.php @@ -69,8 +69,8 @@ abstract class AbstractCalculator public function getTax(): float { $vat = $this->getVat(); - if (0 === $vat) { - return 0; + if (0.00 === $vat) { + return 0.00; } $percent = $vat / 100.00; diff --git a/src/Repository/Query/TimesheetQuery.php b/src/Repository/Query/TimesheetQuery.php index 0244aee7..070086cb 100644 --- a/src/Repository/Query/TimesheetQuery.php +++ b/src/Repository/Query/TimesheetQuery.php @@ -144,10 +144,6 @@ class TimesheetQuery extends ActivityQuery */ public function setState($state) { - if (!is_int($state) && $state !== (int) $state) { - return $this; - } - $state = (int) $state; if (in_array($state, [self::STATE_ALL, self::STATE_RUNNING, self::STATE_STOPPED], true)) { $this->state = $state; @@ -170,10 +166,6 @@ class TimesheetQuery extends ActivityQuery */ public function setExported($exported) { - if (!is_int($exported) && $exported !== (int) $exported) { - return $this; - } - $exported = (int) $exported; if (in_array($exported, [self::STATE_ALL, self::STATE_EXPORTED, self::STATE_NOT_EXPORTED], true)) { $this->exported = $exported; @@ -182,10 +174,7 @@ class TimesheetQuery extends ActivityQuery return $this; } - /** - * @return \DateTime - */ - public function getBegin() + public function getBegin(): ?\DateTime { return $this->dateRange->getBegin(); } @@ -201,10 +190,7 @@ class TimesheetQuery extends ActivityQuery return $this; } - /** - * @return \DateTime - */ - public function getEnd() + public function getEnd(): ?\DateTime { return $this->dateRange->getEnd(); } diff --git a/src/Repository/Query/UserQuery.php b/src/Repository/Query/UserQuery.php index cb9d8077..7a9a232a 100644 --- a/src/Repository/Query/UserQuery.php +++ b/src/Repository/Query/UserQuery.php @@ -19,7 +19,7 @@ class UserQuery extends VisibilityQuery /** * @var string|null */ - protected $role; + private $role; public function __construct() { @@ -37,12 +37,12 @@ class UserQuery extends VisibilityQuery } /** - * @param string $role + * @param string|null $role * @return UserQuery */ public function setRole($role) { - if (false !== strpos($role, 'ROLE_') || null === $role) { + if (null === $role || false !== strpos($role, 'ROLE_')) { $this->role = $role; } diff --git a/src/Repository/Query/VisibilityQuery.php b/src/Repository/Query/VisibilityQuery.php index 6e556865..ca0691ca 100644 --- a/src/Repository/Query/VisibilityQuery.php +++ b/src/Repository/Query/VisibilityQuery.php @@ -43,10 +43,6 @@ class VisibilityQuery extends BaseQuery */ public function setVisibility($visibility) { - if (!is_int($visibility) && $visibility != (int) $visibility) { - return $this; - } - $visibility = (int) $visibility; if (in_array($visibility, self::ALLOWED_VISIBILITY_STATES, true)) { $this->visibility = $visibility; diff --git a/src/Utils/Duration.php b/src/Utils/Duration.php index ce42c2d8..3aa7bebb 100644 --- a/src/Utils/Duration.php +++ b/src/Utils/Duration.php @@ -24,7 +24,7 @@ class Duration /** * Transforms seconds into a duration string. * - * @param int $seconds + * @param int|null $seconds * @param string $format * @return string|null */ diff --git a/src/Validator/Constraints/TimesheetValidator.php b/src/Validator/Constraints/TimesheetValidator.php index 6f47f42a..6b0e064e 100644 --- a/src/Validator/Constraints/TimesheetValidator.php +++ b/src/Validator/Constraints/TimesheetValidator.php @@ -46,7 +46,7 @@ class TimesheetValidator extends ConstraintValidator } /** - * @param TimesheetEntity $value + * @param TimesheetEntity|mixed $value * @param Constraint $constraint */ public function validate($value, Constraint $constraint) diff --git a/symfony.lock b/symfony.lock index 26b7fc00..67d3e39f 100644 --- a/symfony.lock +++ b/symfony.lock @@ -426,6 +426,9 @@ "sebastian/resource-operations": { "version": "1.0.0" }, + "sebastian/type": { + "version": "1.1.3" + }, "sebastian/version": { "version": "2.0.1" }, diff --git a/tests/API/ApiDocControllerTest.php b/tests/API/ApiDocControllerTest.php index 508c133d..755e8583 100644 --- a/tests/API/ApiDocControllerTest.php +++ b/tests/API/ApiDocControllerTest.php @@ -26,14 +26,14 @@ class ApiDocControllerTest extends ControllerBaseTest { $client = $this->getClientForAuthenticatedUser(User::ROLE_USER); $this->assertAccessIsGranted($client, '/api/doc'); - $this->assertContains('Kimai 2 - API Docs', $client->getResponse()->getContent()); + $this->assertStringContainsString('Kimai 2 - API Docs', $client->getResponse()->getContent()); } public function testGetJsonDocs() { $client = $this->getClientForAuthenticatedUser(User::ROLE_USER); $this->assertAccessIsGranted($client, '/api/doc.json'); - $this->assertContains('"title":"Kimai 2 - API Docs"', $client->getResponse()->getContent()); + $this->assertStringContainsString('"title":"Kimai 2 - API Docs"', $client->getResponse()->getContent()); $result = json_decode($client->getResponse()->getContent(), true); $this->assertIsArray($result); $this->assertNotEmpty($result); diff --git a/tests/API/TagControllerTest.php b/tests/API/TagControllerTest.php index ea225f2b..1967eced 100644 --- a/tests/API/TagControllerTest.php +++ b/tests/API/TagControllerTest.php @@ -18,7 +18,7 @@ use Symfony\Component\HttpFoundation\Response; */ class TagControllerTest extends APIControllerBaseTest { - public function setUp() + protected function setUp(): void { $client = $this->getClientForAuthenticatedUser(User::ROLE_USER); $em = $client->getContainer()->get('doctrine.orm.entity_manager'); diff --git a/tests/API/TimesheetControllerTest.php b/tests/API/TimesheetControllerTest.php index 2d02fac0..64f5cc81 100644 --- a/tests/API/TimesheetControllerTest.php +++ b/tests/API/TimesheetControllerTest.php @@ -36,7 +36,7 @@ class TimesheetControllerTest extends APIControllerBaseTest */ protected $dateTime; - public function setUp() + protected function setUp(): void { $this->importFixtureForUser(User::ROLE_USER); $this->dateTime = (new UserDateTimeFactoryFactory($this))->create(self::TEST_TIMEZONE); diff --git a/tests/Command/CreateUserCommandTest.php b/tests/Command/CreateUserCommandTest.php index 6652f88a..c26155fa 100644 --- a/tests/Command/CreateUserCommandTest.php +++ b/tests/Command/CreateUserCommandTest.php @@ -26,7 +26,7 @@ class CreateUserCommandTest extends KernelTestCase */ protected $application; - protected function setUp() + protected function setUp(): void { $kernel = self::bootKernel(); $this->application = new Application($kernel); @@ -46,8 +46,8 @@ class CreateUserCommandTest extends KernelTestCase $commandTester = $this->createUser('MyTestUser', 'user@example.com', 'ROLE_USER', 'foobar'); $output = $commandTester->getDisplay(); - $this->assertContains('[ERROR] plainPassword (foobar)', $output); - $this->assertContains('The password is too short.', $output); + $this->assertStringContainsString('[ERROR] plainPassword (foobar)', $output); + $this->assertStringContainsString('The password is too short.', $output); } public function testCreateUser() @@ -55,7 +55,7 @@ class CreateUserCommandTest extends KernelTestCase $commandTester = $this->createUser('MyTestUser', 'user@example.com', 'ROLE_USER', 'foobar12'); $output = $commandTester->getDisplay(); - $this->assertContains('[OK] Success! Created user: MyTestUser', $output); + $this->assertStringContainsString('[OK] Success! Created user: MyTestUser', $output); $container = self::$kernel->getContainer(); $user = $container->get('doctrine')->getRepository(User::class)->loadUserByUsername('MyTestUser'); @@ -82,10 +82,10 @@ class CreateUserCommandTest extends KernelTestCase { $commandTester = $this->createUser('xx', '', 'ROLE_USER', ''); $output = $commandTester->getDisplay(); - $this->assertContains('[ERROR] email ()', $output); - $this->assertContains('Please enter an email', $output); - $this->assertContains('[ERROR] plainPassword ()', $output); - $this->assertContains('Please enter a password', $output); + $this->assertStringContainsString('[ERROR] email ()', $output); + $this->assertStringContainsString('Please enter an email', $output); + $this->assertStringContainsString('[ERROR] plainPassword ()', $output); + $this->assertStringContainsString('Please enter a password', $output); } public function testUserAlreadyExisting() @@ -94,8 +94,8 @@ class CreateUserCommandTest extends KernelTestCase $commandTester = $this->createUser('MyTestUser', 'user@example.com', 'ROLE_USER', 'foobar'); $output = $commandTester->getDisplay(); - $this->assertContains('[ERROR] username (mytestuser)', $output); - $this->assertContains('The username is already used', $output); + $this->assertStringContainsString('[ERROR] username (mytestuser)', $output); + $this->assertStringContainsString('The username is already used', $output); } public function testUserEmail() @@ -103,7 +103,7 @@ class CreateUserCommandTest extends KernelTestCase $commandTester = $this->createUser('MyTestUser', 'ROLE_USER', 'ROLE_USER', 'foobar12'); $output = $commandTester->getDisplay(); - $this->assertContains('[ERROR] email (ROLE_USER)', $output); - $this->assertContains('The email is not valid', $output); + $this->assertStringContainsString('[ERROR] email (ROLE_USER)', $output); + $this->assertStringContainsString('The email is not valid', $output); } } diff --git a/tests/Command/InstallCommandTest.php b/tests/Command/InstallCommandTest.php index 6e9b5cc7..62b5bb6a 100644 --- a/tests/Command/InstallCommandTest.php +++ b/tests/Command/InstallCommandTest.php @@ -57,13 +57,13 @@ class InstallCommandTest extends KernelTestCase $result = $commandTester->getDisplay(); - self::assertContains('var/cache/', $result); - self::assertContains('var/data/', $result); - self::assertContains('var/log/', $result); - self::assertContains('var/plugins/', $result); - self::assertContains('var/sessions/', $result); + self::assertStringContainsString('var/cache/', $result); + self::assertStringContainsString('var/data/', $result); + self::assertStringContainsString('var/log/', $result); + self::assertStringContainsString('var/plugins/', $result); + self::assertStringContainsString('var/sessions/', $result); self::assertEquals(5, substr_count($result, 'missing: read owner,read group,write group')); - self::assertContains('[WARNING] Aborting installation to review the permissions for above mentioned', $result); + self::assertStringContainsString('[WARNING] Aborting installation to review the permissions for above mentioned', $result); self::assertEquals(InstallCommand::ERROR_PERMISSIONS, $commandTester->getStatusCode()); } @@ -79,17 +79,17 @@ class InstallCommandTest extends KernelTestCase $result = $commandTester->getDisplay(); // create database is skipped - self::assertContains('[NOTE] Database is existing and connection could be established', $result); + self::assertStringContainsString('[NOTE] Database is existing and connection could be established', $result); // create schema is skipped - self::assertContains('[NOTE] It seems as if you already have the required tables in your database,', $result); - self::assertContains('skipping schema creation', $result); + self::assertStringContainsString('[NOTE] It seems as if you already have the required tables in your database,', $result); + self::assertStringContainsString('skipping schema creation', $result); // make sure migrations run always - self::assertContains('Application Migrations', $result); - self::assertContains('No migrations to execute.', $result); + self::assertStringContainsString('Application Migrations', $result); + self::assertStringContainsString('No migrations to execute.', $result); - self::assertContains( + self::assertStringContainsString( sprintf('[OK] Congratulations! Kimai 2 (%s %s) was successful installed!', Constants::VERSION, Constants::STATUS), $result ); diff --git a/tests/Command/PluginCommandTest.php b/tests/Command/PluginCommandTest.php index 113cefc9..ab7a31ea 100644 --- a/tests/Command/PluginCommandTest.php +++ b/tests/Command/PluginCommandTest.php @@ -39,10 +39,10 @@ class PluginCommandTest extends KernelTestCase $commandTester = $this->getCommandTester([$plugin1, $plugin2], []); $output = $commandTester->getDisplay(); - $this->assertContains(__DIR__, $output); - $this->assertContains('BundleDirectory', $output); - $this->assertContains('Test-Bundle', $output); - $this->assertContains('Another one', $output); + $this->assertStringContainsString(__DIR__, $output); + $this->assertStringContainsString('BundleDirectory', $output); + $this->assertStringContainsString('Test-Bundle', $output); + $this->assertStringContainsString('Another one', $output); } protected function getCommandTester(array $plugins, array $options = []) diff --git a/tests/Command/VersionCommandTest.php b/tests/Command/VersionCommandTest.php index 0c1a0c6d..bf9bb7f2 100644 --- a/tests/Command/VersionCommandTest.php +++ b/tests/Command/VersionCommandTest.php @@ -26,7 +26,7 @@ class VersionCommandTest extends KernelTestCase */ protected $application; - protected function setUp() + protected function setUp(): void { $kernel = self::bootKernel(); $this->application = new Application($kernel); diff --git a/tests/Configuration/FormConfigurationTest.php b/tests/Configuration/FormConfigurationTest.php index 4508c5ed..55276cb1 100644 --- a/tests/Configuration/FormConfigurationTest.php +++ b/tests/Configuration/FormConfigurationTest.php @@ -86,12 +86,11 @@ class FormConfigurationTest extends TestCase $this->assertEquals('FR', $sut->find('defaults.customer.country')); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Unknown config: foobar - */ public function testUnknownConfigAreNotImportedAndFindingThemThrowsException() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown config: foobar'); + $sut = $this->getSut($this->getDefaultSettings(), [ (new Configuration())->setName('defaults.customer.foobar')->setValue('hello'), ]); diff --git a/tests/Configuration/LanguageFormattingsTest.php b/tests/Configuration/LanguageFormattingsTest.php index 4afba48f..bd1dc5f5 100644 --- a/tests/Configuration/LanguageFormattingsTest.php +++ b/tests/Configuration/LanguageFormattingsTest.php @@ -97,12 +97,11 @@ class LanguageFormattingsTest extends TestCase $this->assertEquals(['de', 'en', 'pt_BR', 'it', 'fr', 'es', 'ru', 'ar', 'hu'], $sut->getAvailableLanguages()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Unknown locale given: xx - */ public function testInvalidLocaleWithGivenLocale() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown locale given: xx'); + $sut = $this->getSut($this->getDefaultSettings()); $sut->getDateFormat('xx'); } @@ -163,12 +162,11 @@ class LanguageFormattingsTest extends TestCase $this->assertEquals('H:i:s', $sut->getTimeFormat('en')); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Unknown setting for locale en: date_time_type - */ public function testUnknownSetting() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown setting for locale en: date_time_type'); + $sut = $this->getSut(['en' => [ 'xxx' => 'dd.MM.yyyy HH:mm', ]]); diff --git a/tests/Configuration/SystemConfigurationTest.php b/tests/Configuration/SystemConfigurationTest.php index 35dd5bad..1ebc0cb3 100644 --- a/tests/Configuration/SystemConfigurationTest.php +++ b/tests/Configuration/SystemConfigurationTest.php @@ -100,12 +100,11 @@ class SystemConfigurationTest extends TestCase $this->assertEquals(false, $sut->find('timesheet.rules.allow_future_times')); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Unknown config: foo - */ public function testUnknownConfigAreNotImportedAndFindingThemThrowsException() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown config: foo'); + $sut = $this->getSut($this->getDefaultSettings(), [ (new Configuration())->setName('timesheet.foo')->setValue('hello'), ]); diff --git a/tests/Configuration/TimesheetConfigurationTest.php b/tests/Configuration/TimesheetConfigurationTest.php index e16cd709..4bef9362 100644 --- a/tests/Configuration/TimesheetConfigurationTest.php +++ b/tests/Configuration/TimesheetConfigurationTest.php @@ -102,12 +102,11 @@ class TimesheetConfigurationTest extends TestCase $this->assertEquals(false, $sut->find('timesheet.rules.allow_future_times')); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Unknown config: foo - */ public function testUnknownConfigAreNotImportedAndFindingThemThrowsException() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown config: foo'); + $sut = $this->getSut($this->getDefaultSettings(), [ (new Configuration())->setName('timesheet.foo')->setValue('hello'), ]); diff --git a/tests/Controller/AboutControllerTest.php b/tests/Controller/AboutControllerTest.php index 4afbab96..47ce8e6d 100644 --- a/tests/Controller/AboutControllerTest.php +++ b/tests/Controller/AboutControllerTest.php @@ -26,6 +26,6 @@ class AboutControllerTest extends ControllerBaseTest $result = $client->getCrawler()->filter('div.box-body pre'); $this->assertEquals(1, count($result)); - $this->assertContains('MIT License', $result->text()); + $this->assertStringContainsString('MIT License', $result->text()); } } diff --git a/tests/Controller/CalendarControllerTest.php b/tests/Controller/CalendarControllerTest.php index a087131c..e5c40a0c 100644 --- a/tests/Controller/CalendarControllerTest.php +++ b/tests/Controller/CalendarControllerTest.php @@ -48,10 +48,10 @@ class CalendarControllerTest extends ControllerBaseTest $this->assertEquals(1, $calendar->count()); $content = $client->getResponse()->getContent(); - $this->assertContains("googleCalendarId: 'de.german#holiday@group.v.calendar.google.com',", $content); - $this->assertContains("name: 'holidays'", $content); - $this->assertContains("googleCalendarId: 'en.german#holiday@group.v.calendar.google.com',", $content); - $this->assertContains("name: 'holidays_en'", $content); + $this->assertStringContainsString("googleCalendarId: 'de.german#holiday@group.v.calendar.google.com',", $content); + $this->assertStringContainsString("name: 'holidays'", $content); + $this->assertStringContainsString("googleCalendarId: 'en.german#holiday@group.v.calendar.google.com',", $content); + $this->assertStringContainsString("name: 'holidays_en'", $content); } protected function getDefaultSettings() diff --git a/tests/Controller/ControllerBaseTest.php b/tests/Controller/ControllerBaseTest.php index 835cdf27..0d82fcb5 100644 --- a/tests/Controller/ControllerBaseTest.php +++ b/tests/Controller/ControllerBaseTest.php @@ -147,7 +147,7 @@ abstract class ControllerBaseTest extends WebTestCase $client->getResponse()->isSuccessful(), 'Access is not denied for URL: ' . $client->getRequest()->getUri() ); - self::assertContains( + self::assertStringContainsString( 'Symfony\Component\Security\Core\Exception\AccessDeniedException', $client->getResponse()->getContent(), 'Could not find AccessDeniedException in response' @@ -168,7 +168,7 @@ abstract class ControllerBaseTest extends WebTestCase protected function assertMainContentClass(Client $client, string $classname) { - self::assertContains('
', $client->getResponse()->getContent()); + self::assertStringContainsString('
', $client->getResponse()->getContent()); } /** @@ -176,7 +176,7 @@ abstract class ControllerBaseTest extends WebTestCase */ protected function assertHasDataTable(Client $client) { - self::assertContains('', $content); - $this->assertContains('', $content); - $this->assertContains('', $content); - $this->assertContains('', $content); + $this->assertStringContainsString('', $content); - $this->assertContains('', $content); - $this->assertContains('', $content); - $this->assertContains('', $content); + $this->assertStringContainsString('', $content); + $this->assertStringContainsString('', $content); + $this->assertStringContainsString('', $content); + $this->assertStringContainsString('', $content); // 5 times in the "full list" and once in the "summary with activities" $this->assertEquals(6, substr_count($content, 'activity description')); diff --git a/tests/Form/DataTransformer/DurationStringToSecondsTransformerTest.php b/tests/Form/DataTransformer/DurationStringToSecondsTransformerTest.php index 9defc35a..b526df74 100644 --- a/tests/Form/DataTransformer/DurationStringToSecondsTransformerTest.php +++ b/tests/Form/DataTransformer/DurationStringToSecondsTransformerTest.php @@ -11,6 +11,7 @@ namespace App\Tests\Form\DataTransformer; use App\Form\DataTransformer\DurationStringToSecondsTransformer; use PHPUnit\Framework\TestCase; +use Symfony\Component\Form\Exception\TransformationFailedException; /** * @covers \App\Form\DataTransformer\DurationStringToSecondsTransformer @@ -22,7 +23,7 @@ class DurationStringToSecondsTransformerTest extends TestCase */ private $sut; - protected function setUp() + protected function setUp(): void { $this->sut = new DurationStringToSecondsTransformer(); } @@ -55,10 +56,11 @@ class DurationStringToSecondsTransformerTest extends TestCase /** * @dataProvider getInvalidTestDataTransform - * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException */ public function testInvalidTransformThrowsException($transform) { + $this->expectException(TransformationFailedException::class); + $this->sut->transform($transform); } @@ -91,10 +93,11 @@ class DurationStringToSecondsTransformerTest extends TestCase /** * @dataProvider getInvalidTestDataReverseTransform - * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException */ public function testInvalidReverseTransformThrowsException($transform) { + $this->expectException(TransformationFailedException::class); + $this->sut->reverseTransform($transform); } } diff --git a/tests/Invoice/Renderer/CsvRendererTest.php b/tests/Invoice/Renderer/CsvRendererTest.php index 185ca5c7..4b4769fd 100644 --- a/tests/Invoice/Renderer/CsvRendererTest.php +++ b/tests/Invoice/Renderer/CsvRendererTest.php @@ -62,8 +62,8 @@ class CsvRendererTest extends TestCase $this->assertTrue(file_exists($file->getRealPath())); $content = file_get_contents($file->getRealPath()); - $this->assertNotContains('${', $content); - $this->assertContains(',"' . $expectedRate . '"', $content); + $this->assertStringNotContainsString('${', $content); + $this->assertStringContainsString(',"' . $expectedRate . '"', $content); $this->assertEquals($expectedRows, substr_count($content, PHP_EOL)); $this->assertEquals($expectedDescriptions, substr_count($content, 'activity description')); $this->assertEquals($expectedUser1, substr_count($content, ',"kevin",')); diff --git a/tests/Invoice/Renderer/DocxRendererTest.php b/tests/Invoice/Renderer/DocxRendererTest.php index 8d2abae3..8b0423a0 100644 --- a/tests/Invoice/Renderer/DocxRendererTest.php +++ b/tests/Invoice/Renderer/DocxRendererTest.php @@ -55,7 +55,7 @@ class DocxRendererTest extends TestCase /* $content = file_get_contents($file->getRealPath()); $this->assertNotContains('${', $content); - $this->assertContains(',"1,947.99" ', $content); + $this->assertStringContainsString(',"1,947.99" ', $content); $this->assertEquals(6, substr_count($content, PHP_EOL)); $this->assertEquals(5, substr_count($content, 'activity description')); $this->assertEquals(1, substr_count($content, ',"kevin",')); diff --git a/tests/Invoice/Renderer/OdsRendererTest.php b/tests/Invoice/Renderer/OdsRendererTest.php index bcbac3cb..2f56c170 100644 --- a/tests/Invoice/Renderer/OdsRendererTest.php +++ b/tests/Invoice/Renderer/OdsRendererTest.php @@ -66,7 +66,7 @@ class OdsRendererTest extends TestCase /* $content = file_get_contents($file->getRealPath()); $this->assertNotContains('${', $content); - $this->assertContains(',"1,947.99" ', $content); + $this->assertStringContainsString(',"1,947.99" ', $content); $this->assertEquals(6, substr_count($content, PHP_EOL)); $this->assertEquals(5, substr_count($content, 'activity description')); $this->assertEquals(1, substr_count($content, ',"kevin",')); diff --git a/tests/Invoice/Renderer/TwigRendererTest.php b/tests/Invoice/Renderer/TwigRendererTest.php index e6746efe..46a3c825 100644 --- a/tests/Invoice/Renderer/TwigRendererTest.php +++ b/tests/Invoice/Renderer/TwigRendererTest.php @@ -62,7 +62,7 @@ class TwigRendererTest extends KernelTestCase $content = $response->getContent(); - $this->assertContains('', $content); $this->assertEquals(5, substr_count($content, 'activity description')); diff --git a/tests/Invoice/Renderer/XlsxRendererTest.php b/tests/Invoice/Renderer/XlsxRendererTest.php index 1f0d528b..43ad38a7 100644 --- a/tests/Invoice/Renderer/XlsxRendererTest.php +++ b/tests/Invoice/Renderer/XlsxRendererTest.php @@ -66,7 +66,7 @@ class XlsxRendererTest extends TestCase /* $content = file_get_contents($file->getRealPath()); $this->assertNotContains('${', $content); - $this->assertContains(',"1,947.99" ', $content); + $this->assertStringContainsString(',"1,947.99" ', $content); $this->assertEquals(6, substr_count($content, PHP_EOL)); $this->assertEquals(5, substr_count($content, 'activity description')); $this->assertEquals(1, substr_count($content, ',"kevin",')); diff --git a/tests/Ldap/LdapAuthenticationProviderTest.php b/tests/Ldap/LdapAuthenticationProviderTest.php index db04ffc0..577c2638 100644 --- a/tests/Ldap/LdapAuthenticationProviderTest.php +++ b/tests/Ldap/LdapAuthenticationProviderTest.php @@ -16,6 +16,8 @@ use App\Ldap\LdapManager; use App\Ldap\LdapUserProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; +use Symfony\Component\Security\Core\Exception\AuthenticationServiceException; +use Symfony\Component\Security\Core\Exception\BadCredentialsException; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\User\UserChecker; @@ -39,12 +41,11 @@ class LdapAuthenticationProviderTest extends TestCase self::assertTrue($result); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException - * @expectedExceptionMessage The password in the token is empty. Check `erase_credentials` in your `security.yaml` - */ public function testAuthenticateWithTokenUserButEmptyPasswordThrowsException() { + $this->expectException(BadCredentialsException::class); + $this->expectExceptionMessage('The password in the token is empty. Check `erase_credentials` in your `security.yaml`'); + $manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock(); $config = new LdapConfiguration([]); $userProvider = new LdapUserProvider($manager); @@ -58,12 +59,11 @@ class LdapAuthenticationProviderTest extends TestCase $actual = $sut->authenticate($token); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException - * @expectedExceptionMessage The presented password cannot be empty. - */ public function testAuthenticateWithUsernameReturnsUser() { + $this->expectException(BadCredentialsException::class); + $this->expectExceptionMessage('The presented password cannot be empty.'); + $user = (new User())->setUsername('foo')->setEnabled(true); $manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock(); $config = new LdapConfiguration([]); @@ -78,12 +78,11 @@ class LdapAuthenticationProviderTest extends TestCase $actual = $sut->authenticate($token); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException - * @expectedExceptionMessage The presented password is invalid. - */ public function testAuthenticateWithUsernameThrowsExceptionOnFailedBind() { + $this->expectException(BadCredentialsException::class); + $this->expectExceptionMessage('The presented password is invalid.'); + $user = (new User())->setUsername('foo')->setEnabled(true); $manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->setMethods(['bind'])->getMock(); $manager->expects($this->once())->method('bind')->willReturn(false); @@ -99,12 +98,11 @@ class LdapAuthenticationProviderTest extends TestCase $actual = $sut->authenticate($token); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException - * @expectedExceptionMessage The credentials were changed from another session. - */ public function testAuthenticateWithUserThrowsExceptionOnFailedBind() { + $this->expectException(BadCredentialsException::class); + $this->expectExceptionMessage('The credentials were changed from another session.'); + $user = (new User())->setUsername('foo')->setEnabled(true); $manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->setMethods(['bind'])->getMock(); $manager->expects($this->once())->method('bind')->willReturn(false); @@ -164,12 +162,11 @@ class LdapAuthenticationProviderTest extends TestCase self::assertSame($token->getUser(), $user); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException - * @expectedExceptionMessage blub foo bar - */ public function testAuthenticateThrowsExceptionOnLdapNotFound() { + $this->expectException(UsernameNotFoundException::class); + $this->expectExceptionMessage('blub foo bar'); + $manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock(); $config = new LdapConfiguration([]); $userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock(); @@ -183,13 +180,12 @@ class LdapAuthenticationProviderTest extends TestCase $sut->authenticate($token); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationServiceException - * @expectedExceptionMessage server away - * @expectedExceptionCode 1234 - */ public function testAuthenticateThrowsExceptionOnLdapDown() { + $this->expectException(AuthenticationServiceException::class); + $this->expectExceptionMessage('server away'); + $this->expectExceptionCode('1234'); + $manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->getMock(); $config = new LdapConfiguration([]); $userProvider = $this->getMockBuilder(LdapUserProvider::class)->disableOriginalConstructor()->setMethods(['loadUserByUsername'])->getMock(); diff --git a/tests/Ldap/LdapDriverTest.php b/tests/Ldap/LdapDriverTest.php index 0c327c93..9a25f34f 100644 --- a/tests/Ldap/LdapDriverTest.php +++ b/tests/Ldap/LdapDriverTest.php @@ -11,6 +11,7 @@ namespace App\Tests\Ldap; use App\Entity\User; use App\Ldap\LdapDriver; +use App\Ldap\LdapDriverException; use PHPUnit\Framework\TestCase; use Zend\Ldap\Exception\LdapException; use Zend\Ldap\Ldap; @@ -20,7 +21,7 @@ use Zend\Ldap\Ldap; */ class LdapDriverTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); if (!class_exists('Zend\Ldap\Ldap')) { @@ -61,12 +62,11 @@ class LdapDriverTest extends TestCase self::assertEquals(['count' => 3, 1, 2, 3], $result); } - /** - * @expectedException \App\Ldap\LdapDriverException - * @expectedExceptionMessage An error occurred with the search operation. - */ public function testSearchException() { + $this->expectException(LdapDriverException::class); + $this->expectExceptionMessage('An error occurred with the search operation.'); + $zendLdap = $this->getMockBuilder(Ldap::class)->disableOriginalConstructor()->setMethods(['bind', 'searchEntries'])->getMock(); $zendLdap->expects($this->once())->method('bind'); $zendLdap->expects($this->once())->method('searchEntries')->willThrowException( diff --git a/tests/Ldap/LdapManagerTest.php b/tests/Ldap/LdapManagerTest.php index 8fbba51f..6e0b3544 100644 --- a/tests/Ldap/LdapManagerTest.php +++ b/tests/Ldap/LdapManagerTest.php @@ -12,6 +12,7 @@ namespace App\Tests\Ldap; use App\Configuration\LdapConfiguration; use App\Entity\User; use App\Ldap\LdapDriver; +use App\Ldap\LdapDriverException; use App\Ldap\LdapManager; use App\Ldap\LdapUserHydrator; use App\Security\RoleService; @@ -77,12 +78,11 @@ class LdapManagerTest extends TestCase self::assertNull($actual); } - /** - * @expectedException \App\Ldap\LdapDriverException - * @expectedExceptionMessage This search must only return a single user - */ public function testFindUserByUsernameOnMultiResults() { + $this->expectException(LdapDriverException::class); + $this->expectExceptionMessage('This search must only return a single user'); + $expected = [ 'count' => 3 ]; @@ -138,12 +138,11 @@ class LdapManagerTest extends TestCase self::assertNull($actual); } - /** - * @expectedException \App\Ldap\LdapDriverException - * @expectedExceptionMessage This search must only return a single user - */ public function testFindUserByOnMultiResults() { + $this->expectException(LdapDriverException::class); + $this->expectExceptionMessage('This search must only return a single user'); + $expected = [ 'count' => 3 ]; @@ -232,12 +231,11 @@ class LdapManagerTest extends TestCase self::assertEquals($userOrig, $user); } - /** - * @expectedException \App\Ldap\LdapDriverException - * @expectedExceptionMessage This search must only return a single user - */ public function testUpdateUserOnMultiResults() { + $this->expectException(LdapDriverException::class); + $this->expectExceptionMessage('This search must only return a single user'); + $user = (new User())->setUsername('foobar'); $user->setPreferenceValue('ldap.dn', 'xxxxxxx'); diff --git a/tests/Ldap/LdapUserProviderTest.php b/tests/Ldap/LdapUserProviderTest.php index a7de505c..afdd2716 100644 --- a/tests/Ldap/LdapUserProviderTest.php +++ b/tests/Ldap/LdapUserProviderTest.php @@ -13,18 +13,18 @@ use App\Entity\User; use App\Ldap\LdapManager; use App\Ldap\LdapUserProvider; use PHPUnit\Framework\TestCase; +use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; /** * @covers \App\Ldap\LdapUserProvider */ class LdapUserProviderTest extends TestCase { - /** - * @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException - * @expectedExceptionMessage User "test" not found - */ public function testLoadUserByUsernameReturnsNull() { + $this->expectException(UsernameNotFoundException::class); + $this->expectExceptionMessage('User "test" not found'); + $manager = $this->getMockBuilder(LdapManager::class)->disableOriginalConstructor()->setMethods(['findUserByUsername'])->getMock(); $manager->expects($this->once())->method('findUserByUsername')->willReturn(null); diff --git a/tests/Ldap/SanitizingExceptionTest.php b/tests/Ldap/SanitizingExceptionTest.php index 6ef58703..5c14caf9 100644 --- a/tests/Ldap/SanitizingExceptionTest.php +++ b/tests/Ldap/SanitizingExceptionTest.php @@ -24,8 +24,8 @@ class SanitizingExceptionTest extends TestCase self::assertInstanceOf(\Exception::class, $sut); - self::assertNotContains('bar', $sut->getMessage()); - self::assertNotContains('bar', (string) $sut); + self::assertStringNotContainsString('bar', $sut->getMessage()); + self::assertStringNotContainsString('bar', (string) $sut); self::assertEquals('Could not find user foo with password **** in your LDAP', $sut->getMessage()); } } diff --git a/tests/Repository/AbstractRepositoryTest.php b/tests/Repository/AbstractRepositoryTest.php index 0617409a..290a525d 100644 --- a/tests/Repository/AbstractRepositoryTest.php +++ b/tests/Repository/AbstractRepositoryTest.php @@ -28,7 +28,7 @@ abstract class AbstractRepositoryTest extends KernelTestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { $kernel = self::bootKernel(); @@ -48,7 +48,7 @@ abstract class AbstractRepositoryTest extends KernelTestCase /** * {@inheritdoc} */ - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); diff --git a/tests/Repository/TagRepositoryTest.php b/tests/Repository/TagRepositoryTest.php index c904f9cb..036ef266 100644 --- a/tests/Repository/TagRepositoryTest.php +++ b/tests/Repository/TagRepositoryTest.php @@ -19,7 +19,7 @@ use App\Tests\DataFixtures\TagFixtures; */ class TagRepositoryTest extends AbstractRepositoryTest { - public function setUp() + protected function setUp(): void { parent::setUp(); $em = $this->getEntityManager(); diff --git a/tests/Repository/WidgetRepositoryTest.php b/tests/Repository/WidgetRepositoryTest.php index 13984c06..18b7dae0 100644 --- a/tests/Repository/WidgetRepositoryTest.php +++ b/tests/Repository/WidgetRepositoryTest.php @@ -14,6 +14,7 @@ use App\Repository\TimesheetRepository; use App\Repository\WidgetRepository; use App\Tests\Mocks\Security\CurrentUserFactory; use App\Widget\Type\CompoundChart; +use App\Widget\WidgetException; use PHPUnit\Framework\TestCase; /** @@ -32,12 +33,11 @@ class WidgetRepositoryTest extends TestCase $this->assertTrue($sut->has('test')); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Cannot find widget "foo". - */ public function testGetWidgetThrowsExceptionOnNonExistingWidget() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Cannot find widget "foo".'); + $repoMock = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock(); $userMock = (new CurrentUserFactory($this))->create(new User()); @@ -45,12 +45,11 @@ class WidgetRepositoryTest extends TestCase $sut->get('foo'); } - /** - * @expectedException \App\Widget\WidgetException - * @expectedExceptionMessage Unknown widget type "FooBar" - */ public function testGetWidgetThrowsExceptionOnInvalidType() { + $this->expectException(WidgetException::class); + $this->expectExceptionMessage('Unknown widget type "FooBar"'); + $repoMock = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock(); $userMock = (new CurrentUserFactory($this))->create(new User()); @@ -58,12 +57,11 @@ class WidgetRepositoryTest extends TestCase $sut->get('test'); } - /** - * @expectedException \App\Widget\WidgetException - * @expectedExceptionMessage Widget type "App\Widget\Type\CompoundChart" is not an instance of "App\Widget\Type\AbstractWidgetType" - */ public function testGetWidgetTriggersExceptionOnWrongClass() { + $this->expectException(WidgetException::class); + $this->expectExceptionMessage('Widget type "App\Widget\Type\CompoundChart" is not an instance of "App\Widget\Type\AbstractWidgetType"'); + $repoMock = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock(); $userMock = (new CurrentUserFactory($this))->create(new User()); diff --git a/tests/Security/UserCheckerTest.php b/tests/Security/UserCheckerTest.php index 808fa347..9d706589 100644 --- a/tests/Security/UserCheckerTest.php +++ b/tests/Security/UserCheckerTest.php @@ -12,6 +12,7 @@ namespace App\Tests\Security; use App\Entity\User; use App\Security\UserChecker; use PHPUnit\Framework\TestCase; +use Symfony\Component\Security\Core\Exception\DisabledException; use Symfony\Component\Security\Core\User\User as SymfonyUser; /** @@ -43,21 +44,19 @@ class UserCheckerTest extends TestCase $this->assertTrue(true); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\DisabledException - * @expectedExceptionMessage User account is disabled. - */ public function testDisabledCannotLoginInCheckPreAuth() { + $this->expectException(DisabledException::class); + $this->expectExceptionMessage('User account is disabled.'); + (new UserChecker())->checkPreAuth((new User())->setEnabled(false)); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\DisabledException - * @expectedExceptionMessage User account is disabled. - */ public function testDisabledCannotLoginInCheckPostAuth() { + $this->expectException(DisabledException::class); + $this->expectExceptionMessage('User account is disabled.'); + (new UserChecker())->checkPostAuth((new User())->setEnabled(false)); } } diff --git a/tests/Timesheet/TrackingModeServiceTest.php b/tests/Timesheet/TrackingModeServiceTest.php index e02d3507..d6e2075b 100644 --- a/tests/Timesheet/TrackingModeServiceTest.php +++ b/tests/Timesheet/TrackingModeServiceTest.php @@ -15,6 +15,7 @@ use App\Tests\Mocks\Security\UserDateTimeFactoryFactory; use App\Timesheet\TrackingMode\PunchInOutMode; use App\Timesheet\TrackingModeService; use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; /** * @covers \App\Timesheet\TrackingModeService @@ -54,12 +55,11 @@ class TrackingModeServiceTest extends TestCase self::assertInstanceOf(PunchInOutMode::class, $sut->getActiveMode()); } - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException - * @expectedExceptionMessage You have requested a non-existent service "xxxxxx" - */ public function testGetActiveModeThrowsExceptionOnlyInvalidMode() { + $this->expectException(ServiceNotFoundException::class); + $this->expectExceptionMessage('You have requested a non-existent service "xxxxxx"'); + $loader = new TestConfigLoader([]); $dateTime = (new UserDateTimeFactoryFactory($this))->create(); $configuration = new TimesheetConfiguration($loader, ['mode' => 'xxxxxx']); diff --git a/tests/Twig/WidgetExtensionTest.php b/tests/Twig/WidgetExtensionTest.php index 6c42dfb5..f44b318f 100644 --- a/tests/Twig/WidgetExtensionTest.php +++ b/tests/Twig/WidgetExtensionTest.php @@ -52,22 +52,20 @@ class WidgetExtensionTest extends TestCase } } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Widget must either implement WidgetInterface or be a string - */ public function testRenderWidgetForInvalidValue() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Widget must either implement WidgetInterface or be a string'); + $sut = $this->getSut(); $sut->renderWidget(true); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Unknown widget "test" requested - */ public function testRenderWidgetForUnknownWidget() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown widget "test" requested'); + $sut = $this->getSut(false); $sut->renderWidget('test'); } diff --git a/tests/Utils/DurationTest.php b/tests/Utils/DurationTest.php index 520fad64..390f7def 100644 --- a/tests/Utils/DurationTest.php +++ b/tests/Utils/DurationTest.php @@ -96,10 +96,11 @@ class DurationTest extends TestCase /** * @dataProvider getParseDurationInvalidData - * @expectedException \InvalidArgumentException */ public function testParseDurationThrowsInvalidArgumentException($duration, $mode) { + $this->expectException(\InvalidArgumentException::class); + $sut = new Duration(); $sut->parseDuration($duration, $mode); } diff --git a/tests/Utils/FileTest.php b/tests/Utils/FileTest.php index 5b3210c9..805c348d 100644 --- a/tests/Utils/FileTest.php +++ b/tests/Utils/FileTest.php @@ -11,18 +11,18 @@ namespace App\Tests\Utils; use App\Utils\File; use PHPUnit\Framework\TestCase; +use Symfony\Component\Filesystem\Exception\FileNotFoundException; /** * @covers \App\Utils\File */ class FileTest extends TestCase { - /** - * @expectedException \Symfony\Component\Filesystem\Exception\FileNotFoundException - * @expectedExceptionMessage Unknown file "/kjhgkjhg/jkhgkjhg" - */ public function testGetPermissionsOnNonExistingFile() { + $this->expectException(FileNotFoundException::class); + $this->expectExceptionMessage('Unknown file "/kjhgkjhg/jkhgkjhg"'); + $sut = new File(); $sut->getPermissions('/kjhgkjhg/jkhgkjhg'); } diff --git a/tests/Utils/LocaleSettingsTest.php b/tests/Utils/LocaleSettingsTest.php index a739982c..f827a5c0 100644 --- a/tests/Utils/LocaleSettingsTest.php +++ b/tests/Utils/LocaleSettingsTest.php @@ -119,21 +119,19 @@ class LocaleSettingsTest extends TestCase $this->assertEquals(['de', 'en', 'pt_BR', 'it', 'fr', 'es', 'ru', 'ar', 'hu'], $sut->getAvailableLanguages()); } - /** - * @expectedException \InvalidArgumentException - */ public function testInvalidLocaleWithDefaultLocale() { + $this->expectException(\InvalidArgumentException::class); + $sut = $this->getSut('en', []); $sut->getDateFormat(); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Unknown locale given: xx - */ public function testInvalidLocaleWithGivenLocale() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown locale given: xx'); + $sut = $this->getSut('xx', $this->getDefaultSettings()); $sut->getDateFormat(); } @@ -192,12 +190,11 @@ class LocaleSettingsTest extends TestCase $this->assertEquals('H:i:s', $sut->getTimeFormat()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Unknown setting for locale en: date_time_type - */ public function testUnknownSetting() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown setting for locale en: date_time_type'); + $sut = $this->getSut('en', ['en' => [ 'xxx' => 'dd.MM.yyyy HH:mm', ]]); diff --git a/tests/Validator/Constraints/DurationValidatorTest.php b/tests/Validator/Constraints/DurationValidatorTest.php index d35b3839..0c4493dc 100644 --- a/tests/Validator/Constraints/DurationValidatorTest.php +++ b/tests/Validator/Constraints/DurationValidatorTest.php @@ -13,6 +13,7 @@ use App\Validator\Constraints\Duration; use App\Validator\Constraints\DurationValidator; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\Regex; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; /** @@ -48,11 +49,10 @@ class DurationValidatorTest extends ConstraintValidatorTestCase ]; } - /** - * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException - */ public function testConstraintIsInvalid() { + $this->expectException(UnexpectedTypeException::class); + $this->validator->validate('foo', new NotBlank()); } diff --git a/tests/Validator/Constraints/RoleValidatorTest.php b/tests/Validator/Constraints/RoleValidatorTest.php index 7bda0d4b..0fd9d757 100644 --- a/tests/Validator/Constraints/RoleValidatorTest.php +++ b/tests/Validator/Constraints/RoleValidatorTest.php @@ -14,6 +14,7 @@ use App\Tests\Mocks\Security\RoleServiceFactory; use App\Validator\Constraints\Role; use App\Validator\Constraints\RoleValidator; use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; /** @@ -39,11 +40,10 @@ class RoleValidatorTest extends ConstraintValidatorTestCase ]; } - /** - * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException - */ public function testConstraintIsInvalid() { + $this->expectException(UnexpectedTypeException::class); + $this->validator->validate('foo', new NotBlank()); } diff --git a/tests/Validator/Constraints/TimesheetValidatorTest.php b/tests/Validator/Constraints/TimesheetValidatorTest.php index 6a9f3191..fa05c96a 100644 --- a/tests/Validator/Constraints/TimesheetValidatorTest.php +++ b/tests/Validator/Constraints/TimesheetValidatorTest.php @@ -21,6 +21,7 @@ use App\Validator\Constraints\Timesheet as TimesheetConstraint; use App\Validator\Constraints\TimesheetValidator; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; /** @@ -46,11 +47,10 @@ class TimesheetValidatorTest extends ConstraintValidatorTestCase return new TimesheetValidator($authMock, $config, $service); } - /** - * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException - */ public function testConstraintIsInvalid() { + $this->expectException(UnexpectedTypeException::class); + $this->validator->validate('foo', new NotBlank()); } diff --git a/tests/Voter/AbstractVoterTest.php b/tests/Voter/AbstractVoterTest.php index ebf8ecf8..5023a904 100644 --- a/tests/Voter/AbstractVoterTest.php +++ b/tests/Voter/AbstractVoterTest.php @@ -14,6 +14,7 @@ use App\Security\AclDecisionManager; use App\Security\RolePermissionManager; use App\Tests\Mocks\Security\RoleServiceFactory; use App\Voter\AbstractVoter; +use Doctrine\Common\Collections\ArrayCollection; use PHPUnit\Framework\TestCase; abstract class AbstractVoterTest extends TestCase @@ -53,7 +54,7 @@ abstract class AbstractVoterTest extends TestCase $user = $this->getMockBuilder(User::class)->getMock(); $user->method('getId')->willReturn($id); $user->method('getRoles')->willReturn($roles); - $user->method('getTeams')->willReturn([]); + $user->method('getTeams')->willReturn(new ArrayCollection()); return $user; } diff --git a/tests/Widget/Type/AbstractContainerTest.php b/tests/Widget/Type/AbstractContainerTest.php index 85e6fbf4..3645ddd9 100644 --- a/tests/Widget/Type/AbstractContainerTest.php +++ b/tests/Widget/Type/AbstractContainerTest.php @@ -56,11 +56,10 @@ abstract class AbstractContainerTest extends TestCase self::assertEquals('bar', $sut->getWidgets()[0]->getTitle()); } - /** - * @expectedException \BadMethodCallException - */ public function testSetOptionNotImplemented() { + $this->expectException(\BadMethodCallException::class); + $sut = $this->createSut(); $sut->setOption('dfsdf', []); } diff --git a/tests/Widget/WidgetServiceTest.php b/tests/Widget/WidgetServiceTest.php index cc54cb8e..7607aac6 100644 --- a/tests/Widget/WidgetServiceTest.php +++ b/tests/Widget/WidgetServiceTest.php @@ -12,6 +12,7 @@ namespace App\Tests\Widget; use App\Repository\WidgetRepository; use App\Widget\Renderer\SimpleWidgetRenderer; use App\Widget\Type\More; +use App\Widget\WidgetException; use App\Widget\WidgetService; use PHPUnit\Framework\TestCase; use Twig\Environment; @@ -50,12 +51,11 @@ class WidgetServiceTest extends TestCase self::assertSame($renderer, $found); } - /** - * @expectedException \App\Widget\WidgetException - * @expectedExceptionMessage No renderer available for widget "App\Widget\Type\More" - */ public function testFindRendererThrowsException() { + $this->expectException(WidgetException::class); + $this->expectExceptionMessage('No renderer available for widget "App\Widget\Type\More"'); + $repository = $this->getMockBuilder(WidgetRepository::class)->disableOriginalConstructor()->getMock(); $sut = new WidgetService($repository, []);
Customer Nameproject name01:50 h€2,437.12Customer Nameproject name01:50 h€2,437.12