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

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