upgraded to phpunit 8 (#1155)

This commit is contained in:
Kevin Papst
2019-10-24 17:35:05 +02:00
committed by GitHub
parent e91e4ff430
commit b0f83291ee
81 changed files with 421 additions and 463 deletions

View File

@@ -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",

166
composer.lock generated
View File

@@ -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",

View File

@@ -138,7 +138,6 @@ class ActivityController extends BaseApiController
*/
public function getAction($id)
{
/** @var Activity $data */
$data = $this->repository->find($id);
if (null === $data) {

View File

@@ -117,7 +117,6 @@ class CustomerController extends BaseApiController
*/
public function getAction($id)
{
/** @var Customer $data */
$data = $this->repository->find($id);
if (null === $data) {

View File

@@ -122,7 +122,6 @@ class ProjectController extends BaseApiController
*/
public function getAction($id)
{
/** @var Project $data */
$data = $this->repository->find($id);
if (null === $data) {

View File

@@ -81,7 +81,6 @@ class TeamController extends BaseApiController
*/
public function getAction($id)
{
/** @var Team $data */
$data = $this->repository->find($id);
if (null === $data) {

View File

@@ -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) {

View File

@@ -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)

View File

@@ -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'

View File

@@ -16,7 +16,7 @@ use Doctrine\DBAL\Types\DateTimeType;
class UTCDateTimeType extends DateTimeType
{
/**
* @var \DateTimeZone
* @var \DateTimeZone|null
*/
private static $utc;

View File

@@ -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;
}

View File

@@ -52,7 +52,6 @@ class TimezoneSubscriber implements EventSubscriberInterface
return false;
}
/* @var $user User */
$user = $this->storage->getToken()->getUser();
if (null === $user) {

View File

@@ -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);
}
}

View File

@@ -46,7 +46,7 @@ class DurationStringToSecondsTransformer implements DataTransformerInterface
}
/**
* @param string $formatToInt
* @param string|null $formatToInt
* @return int|null
*/
public function reverseTransform($formatToInt)

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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
*/

View File

@@ -46,7 +46,7 @@ class TimesheetValidator extends ConstraintValidator
}
/**
* @param TimesheetEntity $value
* @param TimesheetEntity|mixed $value
* @param Constraint $constraint
*/
public function validate($value, Constraint $constraint)

View File

@@ -426,6 +426,9 @@
"sebastian/resource-operations": {
"version": "1.0.0"
},
"sebastian/type": {
"version": "1.1.3"
},
"sebastian/version": {
"version": "2.0.1"
},

View File

@@ -26,14 +26,14 @@ class ApiDocControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/doc');
$this->assertContains('<title>Kimai 2 - API Docs</title>', $client->getResponse()->getContent());
$this->assertStringContainsString('<title>Kimai 2 - API Docs</title>', $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);

View File

@@ -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');

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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
);

View File

@@ -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 = [])

View File

@@ -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);

View File

@@ -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'),
]);

View File

@@ -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',
]]);

View File

@@ -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'),
]);

View File

@@ -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'),
]);

View File

@@ -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());
}
}

View File

@@ -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()

View File

@@ -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('<section class="content ' . $classname . '">', $client->getResponse()->getContent());
self::assertStringContainsString('<section class="content ' . $classname . '">', $client->getResponse()->getContent());
}
/**
@@ -176,7 +176,7 @@ abstract class ControllerBaseTest extends WebTestCase
*/
protected function assertHasDataTable(Client $client)
{
self::assertContains('<table class="table table-striped table-hover dataTable" role="grid" data-reload-event="', $client->getResponse()->getContent());
self::assertStringContainsString('<table class="table table-striped table-hover dataTable" role="grid" data-reload-event="', $client->getResponse()->getContent());
}
/**
@@ -185,9 +185,9 @@ abstract class ControllerBaseTest extends WebTestCase
protected static function assertHasProgressbar(Client $client)
{
$content = $client->getResponse()->getContent();
self::assertContains('<div class="progress-bar progress-bar-', $content);
self::assertContains('" role="progressbar" aria-valuenow="', $content);
self::assertContains('" aria-valuemin="0" aria-valuemax="100" style="width: ', $content);
self::assertStringContainsString('<div class="progress-bar progress-bar-', $content);
self::assertStringContainsString('" role="progressbar" aria-valuenow="', $content);
self::assertStringContainsString('" aria-valuemin="0" aria-valuemax="100" style="width: ', $content);
}
/**
@@ -259,7 +259,7 @@ abstract class ControllerBaseTest extends WebTestCase
/** @var \DOMElement $listMsg */
$listMsg = $field->parents()->getNode(1);
$classes = $listMsg->getAttribute('class');
self::assertContains('has-error', $classes, 'Form field has no validation message: ' . $name);
self::assertStringContainsString('has-error', $classes, 'Form field has no validation message: ' . $name);
}
}
}
@@ -279,7 +279,7 @@ abstract class ControllerBaseTest extends WebTestCase
protected function assertCalloutWidgetWithMessage(Client $client, string $message)
{
$node = $client->getCrawler()->filter('div.callout.callout-warning.lead');
self::assertContains($message, $node->text());
self::assertStringContainsString($message, $node->text());
}
protected function assertHasFlashDeleteSuccess(Client $client)
@@ -301,7 +301,7 @@ abstract class ControllerBaseTest extends WebTestCase
$node = $client->getCrawler()->filter('div.alert.alert-success.alert-dismissible');
self::assertNotEmpty($node->text());
if (null !== $message) {
self::assertContains($message, $node->text());
self::assertStringContainsString($message, $node->text());
}
}
@@ -314,7 +314,7 @@ abstract class ControllerBaseTest extends WebTestCase
$node = $client->getCrawler()->filter('div.alert.alert-error.alert-dismissible');
self::assertNotEmpty($node->text());
if (null !== $message) {
self::assertContains($message, $node->text());
self::assertStringContainsString($message, $node->text());
}
}

View File

@@ -66,9 +66,9 @@ class DashboardControllerTest extends ControllerBaseTest
$content = $client->getResponse()->getContent();
$this->assertContains('<li class="dropdown user-menu">', $content);
$this->assertContains('<a href="/en/profile/' . $user->getUsername() . '">', $content);
$this->assertContains('<a href="/en/profile/' . $user->getUsername() . '/prefs">', $content);
$this->assertContains('<a href="/en/logout">', $content);
$this->assertStringContainsString('<li class="dropdown user-menu">', $content);
$this->assertStringContainsString('<a href="/en/profile/' . $user->getUsername() . '">', $content);
$this->assertStringContainsString('<a href="/en/profile/' . $user->getUsername() . '/prefs">', $content);
$this->assertStringContainsString('<a href="/en/logout">', $content);
}
}

View File

@@ -75,7 +75,7 @@ class ExportControllerTest extends ControllerBaseTest
$response = $client->getResponse();
$this->assertFalse($response->isSuccessful());
$this->assertEquals(404, $response->getStatusCode());
$this->assertContains('Missing export renderer', $response->getContent());
$this->assertStringContainsString('Missing export renderer', $response->getContent());
}
public function testExportActionWithInvalidRenderer()
@@ -97,7 +97,7 @@ class ExportControllerTest extends ControllerBaseTest
$response = $client->getResponse();
$this->assertFalse($response->isSuccessful());
$this->assertEquals(404, $response->getStatusCode());
$this->assertContains('Unknown export renderer', $response->getContent());
$this->assertStringContainsString('Unknown export renderer', $response->getContent());
}
public function testExportAction()
@@ -135,9 +135,9 @@ class ExportControllerTest extends ControllerBaseTest
$this->assertEquals(1, $node->count());
// poor mans assertions ;-)
$this->assertContains('export_print', $node->getIterator()[0]->getAttribute('class'));
$this->assertContains('<h2>List of expenses</h2>', $response->getContent());
$this->assertContains('<h3>Summary</h3>', $response->getContent());
$this->assertStringContainsString('export_print', $node->getIterator()[0]->getAttribute('class'));
$this->assertStringContainsString('<h2>List of expenses</h2>', $response->getContent());
$this->assertStringContainsString('<h3>Summary</h3>', $response->getContent());
$node = $client->getCrawler()->filter('section.export div#export-records table.dataTable tbody tr');
// 20 rows + the summary footer

View File

@@ -64,8 +64,8 @@ class ProfileControllerTest extends ControllerBaseTest
foreach ($dates as $start) {
$year = $start->format('Y');
$this->assertContains('<h3 class="box-title">' . $year . '</h3>', $content);
$this->assertContains('var userProfileChart' . $year . ' = new Chart(', $content);
$this->assertStringContainsString('<h3 class="box-title">' . $year . '</h3>', $content);
$this->assertStringContainsString('var userProfileChart' . $year . ' = new Chart(', $content);
}
$this->assertHasProfileBox($client, 'John Doe');
@@ -87,8 +87,8 @@ class ProfileControllerTest extends ControllerBaseTest
{
$content = $client->getResponse()->getContent();
$this->assertContains('<h3 class="box-title">About me</h3>', $content);
$this->assertContains('<span class="pull-right badge bg-blue">' . $username . '</span>', $content);
$this->assertStringContainsString('<h3 class="box-title">About me</h3>', $content);
$this->assertStringContainsString('<span class="pull-right badge bg-blue">' . $username . '</span>', $content);
}
public function getTabTestData()

View File

@@ -36,15 +36,15 @@ class SecurityControllerTest extends ControllerBaseTest
$this->assertTrue($client->getResponse()->isSuccessful());
$content = $response->getContent();
$this->assertContains('<title>Kimai Time Tracking</title>', $content);
$this->assertContains('<form action="/en/login_check" method="post">', $content);
$this->assertContains('<input type="text" name="_username"', $content);
$this->assertContains('<input name="_password" type="password"', $content);
$this->assertContains('<input id="remember_me" name="_remember_me" type="checkbox"', $content);
$this->assertContains('">Login</button>', $content);
$this->assertContains('<input type="hidden" name="_csrf_token" value="', $content);
$this->assertContains('<a href="/en/register/"', $content);
$this->assertContains('Register a new account', $content);
$this->assertStringContainsString('<title>Kimai Time Tracking</title>', $content);
$this->assertStringContainsString('<form action="/en/login_check" method="post">', $content);
$this->assertStringContainsString('<input type="text" name="_username"', $content);
$this->assertStringContainsString('<input name="_password" type="password"', $content);
$this->assertStringContainsString('<input id="remember_me" name="_remember_me" type="checkbox"', $content);
$this->assertStringContainsString('">Login</button>', $content);
$this->assertStringContainsString('<input type="hidden" name="_csrf_token" value="', $content);
$this->assertStringContainsString('<a href="/en/register/"', $content);
$this->assertStringContainsString('Register a new account', $content);
}
public function testRegisterAccountPageIsRendered()
@@ -56,19 +56,19 @@ class SecurityControllerTest extends ControllerBaseTest
$this->assertTrue($response->isSuccessful());
$content = $response->getContent();
$this->assertContains('<title>Kimai Time Tracking</title>', $content);
$this->assertContains('Register a new account', $content);
$this->assertContains('<form name="fos_user_registration_form" method="post" action="/en/register/" class="fos_user_registration_register">', $content);
$this->assertContains('<input type="email"', $content);
$this->assertContains('id="fos_user_registration_form_email" name="fos_user_registration_form[email]" required="required"', $content);
$this->assertContains('<input type="text"', $content);
$this->assertContains('id="fos_user_registration_form_username" name="fos_user_registration_form[username]" required="required" maxlength="60" pattern=".{3,}"', $content);
$this->assertContains('<input type="password"', $content);
$this->assertContains('id="fos_user_registration_form_plainPassword_first" name="fos_user_registration_form[plainPassword][first]" required="required"', $content);
$this->assertContains('id="fos_user_registration_form_plainPassword_second" name="fos_user_registration_form[plainPassword][second]" required="required"', $content);
$this->assertContains('<input type="hidden"', $content);
$this->assertContains('id="fos_user_registration_form__token" name="fos_user_registration_form[_token]"', $content);
$this->assertContains('>Register</button>', $content);
$this->assertStringContainsString('<title>Kimai Time Tracking</title>', $content);
$this->assertStringContainsString('Register a new account', $content);
$this->assertStringContainsString('<form name="fos_user_registration_form" method="post" action="/en/register/" class="fos_user_registration_register">', $content);
$this->assertStringContainsString('<input type="email"', $content);
$this->assertStringContainsString('id="fos_user_registration_form_email" name="fos_user_registration_form[email]" required="required"', $content);
$this->assertStringContainsString('<input type="text"', $content);
$this->assertStringContainsString('id="fos_user_registration_form_username" name="fos_user_registration_form[username]" required="required" maxlength="60" pattern=".{3,}"', $content);
$this->assertStringContainsString('<input type="password"', $content);
$this->assertStringContainsString('id="fos_user_registration_form_plainPassword_first" name="fos_user_registration_form[plainPassword][first]" required="required"', $content);
$this->assertStringContainsString('id="fos_user_registration_form_plainPassword_second" name="fos_user_registration_form[plainPassword][second]" required="required"', $content);
$this->assertStringContainsString('<input type="hidden"', $content);
$this->assertStringContainsString('id="fos_user_registration_form__token" name="fos_user_registration_form[_token]"', $content);
$this->assertStringContainsString('>Register</button>', $content);
}
public function testRegisterAccount()
@@ -96,8 +96,8 @@ class SecurityControllerTest extends ControllerBaseTest
$this->assertTrue($client->getResponse()->isSuccessful());
$content = $client->getResponse()->getContent();
$this->assertContains('<title>Kimai Time Tracking</title>', $content);
$this->assertContains('<p>Congrats example, your account is now activated.</p>', $content);
$this->assertContains('<a href="/en/homepage">', $content);
$this->assertStringContainsString('<title>Kimai Time Tracking</title>', $content);
$this->assertStringContainsString('<p>Congrats example, your account is now activated.</p>', $content);
$this->assertStringContainsString('<a href="/en/homepage">', $content);
}
}

View File

@@ -17,7 +17,7 @@ use App\Tests\DataFixtures\TagFixtures;
*/
class TagControllerTest extends ControllerBaseTest
{
public function setUp()
protected function setUp(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');

View File

@@ -297,7 +297,7 @@ class TimesheetControllerTest extends ControllerBaseTest
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
$this->assertContains(
$this->assertStringContainsString(
'href="https://www.kimai.org/documentation/timesheet.html"',
$response->getContent(),
'Could not find link to documentation'

View File

@@ -211,7 +211,7 @@ class TimesheetTeamControllerTest extends ControllerBaseTest
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
$this->assertContains(
$this->assertStringContainsString(
'href="https://www.kimai.org/documentation/timesheet.html"',
$response->getContent(),
'Could not find link to documentation'

View File

@@ -10,6 +10,7 @@
namespace App\Tests\DependencyInjection;
use App\DependencyInjection\AppExtension;
use PHPUnit\Framework\Error\Notice;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -23,7 +24,7 @@ class AppExtensionTest extends TestCase
*/
private $extension;
public function setUp()
protected function setUp(): void
{
parent::setUp();
$this->extension = new AppExtension();
@@ -233,13 +234,14 @@ class AppExtensionTest extends TestCase
}
/**
* @expectedException \PHPUnit\Framework\Error\Notice
* @expectedExceptionMessage Found ambiguous configuration. Please remove "kimai.timesheet.duration_only" and set "kimai.timesheet.mode" instead.
* @expectedDeprecation Configuration "kimai.timesheet.duration_only" is deprecated, please remove it
* @group legacy
*/
public function testDurationOnlyDeprecationIsTriggered()
{
$this->expectException(Notice::class);
$this->expectExceptionMessage('Found ambiguous configuration. Please remove "kimai.timesheet.duration_only" and set "kimai.timesheet.mode" instead.');
$minConfig = $this->getMinConfig();
$minConfig['kimai']['timesheet']['duration_only'] = true;
$minConfig['kimai']['timesheet']['mode'] = 'punch';
@@ -349,12 +351,11 @@ class AppExtensionTest extends TestCase
$this->assertEquals(['yyyy', 'xxxx'], $config);
}
/**
* @expectedException \PHPUnit\Framework\Error\Notice
* @expectedExceptionMessage Found invalid "kimai" configuration: The child node "data_dir" at path "kimai" must be configured.
*/
public function testInvalidConfiguration()
{
$this->expectException(Notice::class);
$this->expectExceptionMessage('Found invalid "kimai" configuration: The child node "data_dir" at path "kimai" must be configured.');
$this->extension->load([], $container = $this->getContainer());
}

View File

@@ -11,6 +11,7 @@ namespace App\Tests\DependencyInjection;
use App\DependencyInjection\Configuration;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
/**
* @covers \App\DependencyInjection\Configuration
@@ -43,30 +44,27 @@ class ConfigurationTest extends TestCase
return $node->finalize($normalizedConfig);
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Invalid configuration for path "kimai.data_dir": Data directory does not exist
*/
public function testValidateDataDir()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid configuration for path "kimai.data_dir": Data directory does not exist');
$this->assertConfig($this->getMinConfig('sdfsdfsdfds'), []);
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Invalid configuration for path "kimai.plugin_dir": Plugin directory does not exist
*/
public function testValidatePluginDir()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid configuration for path "kimai.plugin_dir": Plugin directory does not exist');
$this->assertConfig($this->getMinConfig('/tmp/', 'sdfsdfs'), []);
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Invalid configuration for path "kimai.ldap": The "ldap.user.baseDn" config must be set if LDAP is activated.
*/
public function testValidateLdapConfigUserBaseDn()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid configuration for path "kimai.ldap": The "ldap.user.baseDn" config must be set if LDAP is activated.');
$config = $this->getMinConfig();
$config['ldap'] = [
'connection' => [
@@ -77,12 +75,11 @@ class ConfigurationTest extends TestCase
$this->assertConfig($config, []);
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Invalid configuration for path "kimai.ldap.connection": The ldap.connection.useSsl and ldap.connection.useStartTls options are mutually exclusive.
*/
public function testValidateLdapConfig()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid configuration for path "kimai.ldap.connection": The ldap.connection.useSsl and ldap.connection.useStartTls options are mutually exclusive.');
$config = $this->getMinConfig();
$config['ldap'] = [
'connection' => [
@@ -94,12 +91,11 @@ class ConfigurationTest extends TestCase
$this->assertConfig($config, []);
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Invalid configuration for path "kimai.ldap.user.filter": The ldap.user.filter must be enclosed by a matching number of parentheses "()" and must NOT contain a "%s" replacer
*/
public function testValidateLdapFilterIncludingReplacer()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid configuration for path "kimai.ldap.user.filter": The ldap.user.filter must be enclosed by a matching number of parentheses "()" and must NOT contain a "%s" replacer');
$config = $this->getMinConfig();
$config['ldap'] = [
'user' => [
@@ -110,12 +106,11 @@ class ConfigurationTest extends TestCase
$this->assertConfig($config, []);
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Invalid configuration for path "kimai.ldap.user.filter": The ldap.user.filter must be enclosed by a matching number of parentheses "()" and must NOT contain a "%s" replacer
*/
public function testValidateLdapFilterMissingStartingParenthesis()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid configuration for path "kimai.ldap.user.filter": The ldap.user.filter must be enclosed by a matching number of parentheses "()" and must NOT contain a "%s" replacer');
$config = $this->getMinConfig();
$config['ldap'] = [
'user' => [
@@ -126,12 +121,11 @@ class ConfigurationTest extends TestCase
$this->assertConfig($config, []);
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Invalid configuration for path "kimai.ldap.user.filter": The ldap.user.filter must be enclosed by a matching number of parentheses "()" and must NOT contain a "%s" replacer
*/
public function testValidateLdapFilterInvalidParenthesisCounter()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid configuration for path "kimai.ldap.user.filter": The ldap.user.filter must be enclosed by a matching number of parentheses "()" and must NOT contain a "%s" replacer');
$config = $this->getMinConfig();
$config['ldap'] = [
'user' => [
@@ -142,12 +136,11 @@ class ConfigurationTest extends TestCase
$this->assertConfig($config, []);
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Invalid configuration for path "kimai.ldap.connection.accountFilterFormat": The accountFilterFormat must be enclosed by a matching number of parentheses "()" and contain one "%s" replacer for the username
*/
public function testValidateLdapAccountFilterFormatMissingUserAttributeReplacer()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid configuration for path "kimai.ldap.connection.accountFilterFormat": The accountFilterFormat must be enclosed by a matching number of parentheses "()" and contain one "%s" replacer for the username');
$config = $this->getMinConfig();
$config['ldap'] = [
'connection' => [
@@ -158,12 +151,11 @@ class ConfigurationTest extends TestCase
$this->assertConfig($config, []);
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Invalid configuration for path "kimai.ldap.connection.accountFilterFormat": The accountFilterFormat must be enclosed by a matching number of parentheses "()" and contain one "%s" replacer for the username
*/
public function testValidateLdapAccountFilterFormatMissingStartingParenthesis()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid configuration for path "kimai.ldap.connection.accountFilterFormat": The accountFilterFormat must be enclosed by a matching number of parentheses "()" and contain one "%s" replacer for the username');
$config = $this->getMinConfig();
$config['ldap'] = [
'connection' => [
@@ -174,12 +166,11 @@ class ConfigurationTest extends TestCase
$this->assertConfig($config, []);
}
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Invalid configuration for path "kimai.ldap.connection.accountFilterFormat": The accountFilterFormat must be enclosed by a matching number of parentheses "()" and contain one "%s" replacer for the username
*/
public function testValidateLdapAccountFilterFormatInvalidParenthesisCounter()
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid configuration for path "kimai.ldap.connection.accountFilterFormat": The accountFilterFormat must be enclosed by a matching number of parentheses "()" and contain one "%s" replacer for the username');
$config = $this->getMinConfig();
$config['ldap'] = [
'connection' => [

View File

@@ -25,12 +25,11 @@ class TimesheetSubscriberTest extends TestCase
$this->assertTrue(in_array(Events::onFlush, $events));
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid TimesheetCalculator implementation given. Expected CalculatorInterface but received stdClass
*/
public function testConstructThrowsExceptionOnInvalidParam()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid TimesheetCalculator implementation given. Expected CalculatorInterface but received stdClass');
new TimesheetSubscriber([new \stdClass()]);
}
}

View File

@@ -13,6 +13,7 @@ use App\Doctrine\UTCDateTimeType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type;
use PHPUnit\Framework\TestCase;
@@ -83,10 +84,11 @@ class UTCDateTimeTypeTest extends TestCase
/**
* @dataProvider getPlatforms
* @expectedException \Doctrine\DBAL\Types\ConversionException
*/
public function testConvertToPHPValueWithInvalidValue(AbstractPlatform $platform)
{
$this->expectException(ConversionException::class);
Type::overrideType(Type::DATETIME, UTCDateTimeType::class);
/** @var UTCDateTimeType $type */
$type = Type::getType(Type::DATETIME);

View File

@@ -30,12 +30,11 @@ class ActivityMetaTest extends AbstractMetaEntityTest
return new ActivityMeta();
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Expected instanceof Activity, received "App\Entity\Timesheet"
*/
public function testSetEntityThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected instanceof Activity, received "App\Entity\Timesheet"');
$sut = new ActivityMeta();
$sut->setEntity(new Timesheet());
}

View File

@@ -30,12 +30,11 @@ class CustomerMetaTest extends AbstractMetaEntityTest
return new CustomerMeta();
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Expected instanceof Customer, received "App\Entity\Activity"
*/
public function testSetEntityThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected instanceof Customer, received "App\Entity\Activity"');
$sut = new CustomerMeta();
$sut->setEntity(new Activity());
}

View File

@@ -30,12 +30,11 @@ class ProjectMetaTest extends AbstractMetaEntityTest
return new ProjectMeta();
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Expected instanceof Project, received "App\Entity\Customer"
*/
public function testSetEntityThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected instanceof Project, received "App\Entity\Customer"');
$sut = new ProjectMeta();
$sut->setEntity(new Customer());
}

View File

@@ -30,12 +30,11 @@ class TimesheetMetaTest extends AbstractMetaEntityTest
return new TimesheetMeta();
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Expected instanceof Timesheet, received "App\Entity\Project"
*/
public function testSetEntityThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected instanceof Timesheet, received "App\Entity\Project"');
$sut = new TimesheetMeta();
$sut->setEntity(new Project());
}

View File

@@ -36,11 +36,10 @@ class UserPreferenceEventTest extends TestCase
$this->assertEquals([$pref], $sut->getPreferences());
}
/**
* @expectedException \InvalidArgumentException
*/
public function testDuplicatePreferenceThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$user = new User();
$user->setAlias('foo');
$pref = new UserPreference();

View File

@@ -53,9 +53,9 @@ class CsvRendererTest extends AbstractRendererTest
$this->assertTrue(file_exists($file->getRealPath()));
$content = file_get_contents($file->getRealPath());
$this->assertContains('"' . $totalDuration . '"', $content);
$this->assertContains('"' . $totalRate . '"', $content);
$this->assertContains('"' . $expectedRate . '"', $content);
$this->assertStringContainsString('"' . $totalDuration . '"', $content);
$this->assertStringContainsString('"' . $totalRate . '"', $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",'));

View File

@@ -49,17 +49,17 @@ class HtmlRendererTest extends AbstractRendererTest
$content = $response->getContent();
$this->assertContains('<h2>List of expenses</h2>', $content);
$this->assertContains('<h3>Summary</h3>', $content);
$this->assertStringContainsString('<h2>List of expenses</h2>', $content);
$this->assertStringContainsString('<h3>Summary</h3>', $content);
$this->assertEquals(1, substr_count($content, 'id="export-summary"'));
$this->assertEquals(1, substr_count($content, 'id="export-records"'));
$this->assertEquals(1, substr_count($content, 'id="summary-project"'));
$this->assertEquals(1, substr_count($content, 'id="summary-activity"'));
$this->assertContains('<td>Customer Name</td>', $content);
$this->assertContains('<td>project name</td>', $content);
$this->assertContains('<td class="duration">01:50 h</td>', $content);
$this->assertContains('<td class="cost">€2,437.12</td>', $content);
$this->assertStringContainsString('<td>Customer Name</td>', $content);
$this->assertStringContainsString('<td>project name</td>', $content);
$this->assertStringContainsString('<td class="duration">01:50 h</td>', $content);
$this->assertStringContainsString('<td class="cost">€2,437.12</td>', $content);
// 5 times in the "full list" and once in the "summary with activities"
$this->assertEquals(6, substr_count($content, 'activity description'));

View File

@@ -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);
}
}

View File

@@ -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",'));

View File

@@ -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",'));

View File

@@ -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",'));

View File

@@ -62,7 +62,7 @@ class TwigRendererTest extends KernelTestCase
$content = $response->getContent();
$this->assertContains('<h2 class="page-header">
$this->assertStringContainsString('<h2 class="page-header">
<span contenteditable="true">a test invoice template title</span>
</h2>', $content);
$this->assertEquals(5, substr_count($content, 'activity description'));

View File

@@ -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",'));

View File

@@ -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();

View File

@@ -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(

View File

@@ -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');

View File

@@ -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);

View File

@@ -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());
}
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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());

View File

@@ -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));
}
}

View File

@@ -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']);

View File

@@ -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');
}

View File

@@ -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);
}

View File

@@ -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');
}

View File

@@ -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',
]]);

View File

@@ -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());
}

View File

@@ -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());
}

View File

@@ -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());
}

View File

@@ -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;
}

View File

@@ -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', []);
}

View File

@@ -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, []);