update to Symfony 4.4 (#1275)

This commit is contained in:
Kevin Papst
2020-02-04 15:29:26 +01:00
committed by GitHub
parent 375691365e
commit 75dcae6fbe
53 changed files with 1046 additions and 1019 deletions

View File

@@ -21,14 +21,13 @@ class TagControllerTest extends APIControllerBaseTest
protected function setUp(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$tagList = ['Test', 'Administration', 'Support', '#2018-001', '#2018-002', '#2018-003', 'Development',
'Marketing', 'First Level Support', 'Bug Fixing'];
$fixture = new TagFixtures();
$fixture->setTagArray($tagList);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
}
public function testIsSecure()

View File

@@ -13,6 +13,7 @@ use App\Entity\Customer;
use App\Entity\Project;
use App\Entity\User;
use App\Tests\DataFixtures\TeamFixtures;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Component\HttpFoundation\Response;
/**
@@ -20,13 +21,11 @@ use Symfony\Component\HttpFoundation\Response;
*/
class TeamControllerTest extends APIControllerBaseTest
{
protected function setUp(): void
protected function importTeamFixtures(Client $client): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new TeamFixtures();
$fixture->setAmount(1);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
}
public function testIsSecure()
@@ -39,6 +38,7 @@ class TeamControllerTest extends APIControllerBaseTest
public function testGetCollection()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importTeamFixtures($client);
$this->assertAccessIsGranted($client, '/api/teams');
$result = json_decode($client->getResponse()->getContent(), true);
@@ -51,6 +51,7 @@ class TeamControllerTest extends APIControllerBaseTest
public function testGetEntity()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importTeamFixtures($client);
$this->assertAccessIsGranted($client, '/api/teams/2');
$result = json_decode($client->getResponse()->getContent(), true);
@@ -110,7 +111,6 @@ class TeamControllerTest extends APIControllerBaseTest
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$data = [
'name' => 'foo',
'teamlead' => 2,
@@ -129,6 +129,7 @@ class TeamControllerTest extends APIControllerBaseTest
public function testDeleteAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importTeamFixtures($client);
$this->assertAccessIsGranted($client, '/api/teams/2');
$result = json_decode($client->getResponse()->getContent(), true);
@@ -157,7 +158,6 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(1, $result['users']);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/2', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -180,33 +180,28 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
// team not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/999/members/999', 'POST');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Team not found', $json['message']);
// user not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/999', 'POST');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('User not found', $json['message']);
// add user
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/5', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
// cannot add existing member
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/5', 'POST');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('User is already member of the team', $json['message']);
// cannot add disabled user
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/3', 'POST');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -226,7 +221,6 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(4, $result['users']);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/2', 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -249,33 +243,28 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
// team not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/999/members/999', 'DELETE');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Team not found', $json['message']);
// user not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/999', 'DELETE');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('User not found', $json['message']);
// remove user
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/2', 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
// cannot remove non-member
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/2', 'DELETE');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('User is not a member of the team', $json['message']);
// cannot remove teamlead
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/1', 'DELETE');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -294,7 +283,6 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(0, $result['customers']);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/1', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -318,28 +306,24 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
// team not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/999/customers/999', 'POST');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Team not found', $json['message']);
// customer not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/999', 'POST');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Customer not found', $json['message']);
// add customer
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/1', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(1, $result['customers']);
// cannot add existing customer
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/1', 'POST');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -355,7 +339,6 @@ class TeamControllerTest extends APIControllerBaseTest
$em->flush();
// cannot add invisible customer
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/' . $customer->getId(), 'POST');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -376,13 +359,11 @@ class TeamControllerTest extends APIControllerBaseTest
self::assertCount(0, $result['customers']);
// add customer
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/1', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(1, $result['customers']);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/1', 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -405,21 +386,18 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
// team not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/999/customers/999', 'DELETE');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Team not found', $json['message']);
// customer not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/999', 'DELETE');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Customer not found', $json['message']);
// cannot remove customer
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/1', 'DELETE');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -438,7 +416,6 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(0, $result['projects']);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/1', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -462,28 +439,24 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
// team not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/999/projects/999', 'POST');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Team not found', $json['message']);
// project not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/999', 'POST');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Project not found', $json['message']);
// add project
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/1', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(1, $result['projects']);
// cannot add existing project
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/1', 'POST');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -505,7 +478,6 @@ class TeamControllerTest extends APIControllerBaseTest
$em->flush();
// cannot add invisible project
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/' . $project->getId(), 'POST');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -526,13 +498,11 @@ class TeamControllerTest extends APIControllerBaseTest
self::assertCount(0, $result['projects']);
// add project
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/1', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(1, $result['projects']);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/1', 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -555,21 +525,18 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
// team not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/999/projects/999', 'DELETE');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Team not found', $json['message']);
// project not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/999', 'DELETE');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Project not found', $json['message']);
// cannot remove project
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/1', 'DELETE');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);

View File

@@ -56,7 +56,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
->setStartDate((new \DateTime('first day of this month'))->setTime(0, 0, 1))
->setAllowEmptyDescriptions(false)
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
}
public function testIsSecure()
@@ -501,7 +501,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet->setExported(true);
$em->persist($timesheet);
$em->flush($timesheet);
$em->flush();
$this->request($client, '/api/timesheets/1', 'DELETE');
$this->assertApiResponseAccessDenied($client->getResponse(), 'You are not allowed to delete this timesheet');
@@ -516,7 +516,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet->setExported(true);
$em->persist($timesheet);
$em->flush($timesheet);
$em->flush();
$this->request($client, '/api/timesheets/1', 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -734,7 +734,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
$timesheet->setMetaField((new TimesheetMeta())->setName('xxxxxxx')->setValue('asdasdasd'));
$timesheet->setMetaField((new TimesheetMeta())->setName('1234567890')->setValue('1234567890')->setIsVisible(true));
$em->persist($timesheet);
$em->flush($timesheet);
$em->flush();
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$this->assertEquals('foo', $timesheet->getDescription());

View File

@@ -26,6 +26,6 @@ class AboutControllerTest extends ControllerBaseTest
$result = $client->getCrawler()->filter('div.box-body pre');
$this->assertEquals(1, count($result));
$this->assertStringContainsString('MIT License', $result->text());
$this->assertStringContainsString('MIT License', $result->text(null, true));
}
}

View File

@@ -40,7 +40,7 @@ class ActivityControllerTest extends ControllerBaseTest
public function testIndexActionWithSearchTermQuery()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new ActivityFixtures();
$fixture->setAmount(5);
$fixture->setCallback(function (Activity $activity) {
@@ -49,7 +49,7 @@ class ActivityControllerTest extends ControllerBaseTest
$activity->setMetaField((new ActivityMeta())->setName('location')->setValue('homeoffice'));
$activity->setMetaField((new ActivityMeta())->setName('feature')->setValue('timetracking'));
});
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/activity/');
@@ -77,7 +77,7 @@ class ActivityControllerTest extends ControllerBaseTest
$fixture->setAmount(10);
$fixture->setActivities($em->getRepository(Activity::class)->findAll());
$fixture->setUser($this->getUserByRole($em, User::ROLE_ADMIN));
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/activity/1/budget');
@@ -125,11 +125,9 @@ class ActivityControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
/** @var EntityManager $em */
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new ProjectFixtures();
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->assertAccessIsGranted($client, '/admin/activity/create');
$form = $client->getCrawler()->filter('form[name=activity_edit_form]')->form();
@@ -224,10 +222,11 @@ class ActivityControllerTest extends ControllerBaseTest
/** @var EntityManager $em */
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));
@@ -264,13 +263,14 @@ class ActivityControllerTest extends ControllerBaseTest
/** @var EntityManager $em */
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$fixture = new ActivityFixtures();
$fixture->setAmount(1)->setIsGlobal(true)->setIsVisible(true);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));

View File

@@ -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::assertStringContainsString($message, $node->text());
self::assertStringContainsString($message, $node->text(null, true));
}
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::assertGreaterThan(0, $node->count(), 'Could not find flash success message');
if (null !== $message) {
self::assertStringContainsString($message, $node->text());
self::assertStringContainsString($message, $node->text(null, true));
}
}
@@ -314,7 +314,7 @@ abstract class ControllerBaseTest extends WebTestCase
$node = $client->getCrawler()->filter('div.alert.alert-error.alert-dismissible');
self::assertGreaterThan(0, $node->count(), 'Could not find flash error message');
if (null !== $message) {
self::assertStringContainsString($message, $node->text());
self::assertStringContainsString($message, $node->text(null, true));
}
}

View File

@@ -42,7 +42,7 @@ class CustomerControllerTest extends ControllerBaseTest
public function testIndexActionWithSearchTermQuery()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new CustomerFixtures();
$fixture->setAmount(5);
$fixture->setCallback(function (Customer $customer) {
@@ -51,7 +51,7 @@ class CustomerControllerTest extends ControllerBaseTest
$customer->setMetaField((new CustomerMeta())->setName('location')->setValue('homeoffice'));
$customer->setMetaField((new CustomerMeta())->setName('feature')->setValue('timetracking'));
});
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/customer/');
@@ -161,14 +161,14 @@ class CustomerControllerTest extends ControllerBaseTest
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/customer/1/details');
$node = $client->getCrawler()->filter('div.box#team_listing_box .box-body');
self::assertStringContainsString('Visible to everyone, as no team was assigned yet.', $node->text());
self::assertStringContainsString('Visible to everyone, as no team was assigned yet.', $node->text(null, true));
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/admin/customer/1/create_team');
$this->assertIsRedirect($client, $this->createUrl('/admin/customer/1/details'));
$client->followRedirect();
$node = $client->getCrawler()->filter('div.box#team_listing_box .box-body');
self::assertStringContainsString('Only visible to the following teams and all admins.', $node->text());
self::assertStringContainsString('Only visible to the following teams and all admins.', $node->text(null, true));
$node = $client->getCrawler()->filter('div.box#team_listing_box .box-body table tbody tr');
self::assertEquals(1, $node->count());
}
@@ -183,10 +183,11 @@ class CustomerControllerTest extends ControllerBaseTest
/** @var EntityManager $em */
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$customer = $em->getRepository(Customer::class)->find(1);
$fixture = new ProjectFixtures();
$fixture->setAmount(9); // to trigger a second page (every third activity is hidden)
$fixture->setCustomers([$customer]);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/customer/1/projects/1');
@@ -267,7 +268,7 @@ class CustomerControllerTest extends ControllerBaseTest
$fixture = new TeamFixtures();
$fixture->setAmount(2);
$fixture->setAddCustomer(false);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->assertAccessIsGranted($client, '/admin/customer/1/permissions');
$form = $client->getCrawler()->filter('form[name=customer_team_permission_form]')->form();
@@ -292,10 +293,9 @@ class CustomerControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new CustomerFixtures();
$fixture->setAmount(1);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/admin/customer/2/edit');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -322,7 +322,7 @@ class CustomerControllerTest extends ControllerBaseTest
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));
@@ -361,10 +361,10 @@ class CustomerControllerTest extends ControllerBaseTest
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$fixture = new CustomerFixtures();
$fixture->setAmount(1)->setIsVisible(true);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));

View File

@@ -66,7 +66,7 @@ class ExportControllerTest extends ControllerBaseTest
$em->persist($team);
})
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$teamlead = $this->getUserByRole($em, User::ROLE_TEAMLEAD);
@@ -76,7 +76,7 @@ class ExportControllerTest extends ControllerBaseTest
->setAmount(2)
->setStartDate($begin)
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$em->flush();
$this->request($client, '/export/?preview=');
@@ -112,7 +112,7 @@ class ExportControllerTest extends ControllerBaseTest
->setAmount(20)
->setStartDate($begin)
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/export/?preview=');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -128,7 +128,7 @@ class ExportControllerTest extends ControllerBaseTest
->setAmount(2)
->setStartDate($begin)
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/export/?preview=');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -194,7 +194,7 @@ class ExportControllerTest extends ControllerBaseTest
->setAmount(20)
->setStartDate($begin)
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/export/');
$this->assertTrue($client->getResponse()->isSuccessful());

View File

@@ -40,9 +40,8 @@ class InvoiceControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new InvoiceFixtures();
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/invoice/?preview=');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -54,9 +53,8 @@ class InvoiceControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new InvoiceFixtures();
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/invoice/template');
@@ -94,7 +92,7 @@ class InvoiceControllerTest extends ControllerBaseTest
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new InvoiceFixtures();
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
/** @var InvoiceTemplate $template */
$template = $em->getRepository(InvoiceTemplate::class)->find(1);
@@ -123,7 +121,7 @@ class InvoiceControllerTest extends ControllerBaseTest
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new InvoiceFixtures();
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$begin = new \DateTime('first day of this month');
$end = new \DateTime('last day of this month');
@@ -133,7 +131,7 @@ class InvoiceControllerTest extends ControllerBaseTest
->setAmount(20)
->setStartDate($begin)
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/invoice/');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -186,9 +184,8 @@ class InvoiceControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new InvoiceFixtures();
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/invoice/template/1/edit?page=1');
$form = $client->getCrawler()->filter('form[name=invoice_template_form]')->form();
@@ -216,7 +213,7 @@ class InvoiceControllerTest extends ControllerBaseTest
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new InvoiceFixtures();
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/invoice/template/1/delete');
$this->assertIsRedirect($client, '/invoice/template');

View File

@@ -55,7 +55,7 @@ class ProfileControllerTest extends ControllerBaseTest
$fixture->setAmount(10);
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setStartDate($start);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
}
$this->request($client, '/profile/' . UserFixtures::USERNAME_USER);
@@ -338,7 +338,7 @@ class ProfileControllerTest extends ControllerBaseTest
$fixture->setAddCustomer(true);
$fixture->setAddUser(false);
$fixture->addUserToIgnore($user);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/profile/' . UserFixtures::USERNAME_USER . '/teams');

View File

@@ -43,7 +43,7 @@ class ProjectControllerTest extends ControllerBaseTest
public function testIndexActionWithSearchTermQuery()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new ProjectFixtures();
$fixture->setAmount(5);
$fixture->setCallback(function (Project $project) {
@@ -52,7 +52,7 @@ class ProjectControllerTest extends ControllerBaseTest
$project->setMetaField((new ProjectMeta())->setName('location')->setValue('homeoffice'));
$project->setMetaField((new ProjectMeta())->setName('feature')->setValue('timetracking'));
});
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/project/');
@@ -82,13 +82,13 @@ class ProjectControllerTest extends ControllerBaseTest
$fixture->setAmount(10);
$fixture->setProjects([$project]);
$fixture->setUser($this->getUserByRole($em, User::ROLE_ADMIN));
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$project = $em->getRepository(Project::class)->find(1);
$fixture = new ActivityFixtures();
$fixture->setAmount(6); // to trigger a second page
$fixture->setProjects([$project]);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/project/1/details');
@@ -180,14 +180,14 @@ class ProjectControllerTest extends ControllerBaseTest
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/project/1/details');
$node = $client->getCrawler()->filter('div.box#team_listing_box .box-body');
self::assertStringContainsString('Visible to everyone, as no team was assigned yet.', $node->text());
self::assertStringContainsString('Visible to everyone, as no team was assigned yet.', $node->text(null, true));
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/admin/project/1/create_team');
$this->assertIsRedirect($client, $this->createUrl('/admin/project/1/details'));
$client->followRedirect();
$node = $client->getCrawler()->filter('div.box#team_listing_box .box-body');
self::assertStringContainsString('Only visible to the following teams and all admins.', $node->text());
self::assertStringContainsString('Only visible to the following teams and all admins.', $node->text(null, true));
$node = $client->getCrawler()->filter('div.box#team_listing_box .box-body table tbody tr');
self::assertEquals(1, $node->count());
}
@@ -204,7 +204,7 @@ class ProjectControllerTest extends ControllerBaseTest
$fixture = new ActivityFixtures();
$fixture->setAmount(9); // to trigger a second page (every third activity is hidden)
$fixture->setProjects([$project]);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/project/1/activities/1');
@@ -249,10 +249,9 @@ class ProjectControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new CustomerFixtures();
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->assertAccessIsGranted($client, '/admin/project/create');
$form = $client->getCrawler()->filter('form[name=project_edit_form]')->form();
@@ -308,7 +307,7 @@ class ProjectControllerTest extends ControllerBaseTest
$fixture = new TeamFixtures();
$fixture->setAmount(2);
$fixture->setAddCustomer(false);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->assertAccessIsGranted($client, '/admin/project/1/permissions');
$form = $client->getCrawler()->filter('form[name=project_team_permission_form]')->form();
@@ -333,10 +332,9 @@ class ProjectControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new ProjectFixtures();
$fixture->setAmount(1);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/admin/project/2/edit');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -363,7 +361,7 @@ class ProjectControllerTest extends ControllerBaseTest
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));
@@ -402,10 +400,10 @@ class ProjectControllerTest extends ControllerBaseTest
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$fixture = new ProjectFixtures();
$fixture->setAmount(1)->setIsVisible(true);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));

View File

@@ -12,23 +12,21 @@ namespace App\Tests\Controller;
use App\Entity\Tag;
use App\Entity\User;
use App\Tests\DataFixtures\TagFixtures;
use Symfony\Bundle\FrameworkBundle\Client;
/**
* @group integration
*/
class TagControllerTest extends ControllerBaseTest
{
protected function setUp(): void
protected function importTags(Client $client): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$tagList = ['Test', 'Administration', 'Support', '#2018-001', '#2018-002', '#2018-003', 'Development',
'Marketing', 'First Level Support', 'Bug Fixing'];
$fixture = new TagFixtures();
$fixture->setTagArray($tagList);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
}
public function testDebugIsSecure()
@@ -39,6 +37,7 @@ class TagControllerTest extends ControllerBaseTest
public function testIndexAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->importTags($client);
$this->assertAccessIsGranted($client, '/admin/tags/');
$this->assertHasDataTable($client);
@@ -48,6 +47,7 @@ class TagControllerTest extends ControllerBaseTest
public function testIndexActionWithSearchTermQuery()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->importTags($client);
$this->request($client, '/admin/tags/');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -76,7 +76,7 @@ class TagControllerTest extends ControllerBaseTest
$client->followRedirect();
$this->assertHasDataTable($client);
$this->request($client, '/admin/tags/11/edit');
$this->request($client, '/admin/tags/1/edit');
$editForm = $client->getCrawler()->filter('form[name=tag_edit_form]')->form();
$this->assertEquals('A tAG Name!', $editForm->get('tag_edit_form[name]')->getValue());
}
@@ -84,6 +84,8 @@ class TagControllerTest extends ControllerBaseTest
public function testEditAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importTags($client);
$this->assertAccessIsGranted($client, '/admin/tags/1/edit');
$form = $client->getCrawler()->filter('form[name=tag_edit_form]')->form();
$client->submit($form, [
@@ -100,6 +102,8 @@ class TagControllerTest extends ControllerBaseTest
public function testMultiDeleteAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->importTags($client);
$this->assertAccessIsGranted($client, '/admin/tags/');
$form = $client->getCrawler()->filter('form[name=multi_update_table]')->form();

View File

@@ -147,7 +147,7 @@ class UserControllerTest extends ControllerBaseTest
$fixture = new TimesheetFixtures();
$fixture->setUser($user);
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));

View File

@@ -25,11 +25,23 @@ class ThemeEventTest extends TestCase
$sut = new ThemeEvent($user);
$this->assertEquals($user, $sut->getUser());
$this->assertNull($sut->getPayload());
$this->assertEquals('', $sut->getContent());
}
/**
* @group legacy
*/
public function testDeprecation()
{
$user = new User();
$user->setAlias('foo');
$sut = new ThemeEvent($user);
$this->assertEquals($user, $sut->getUser());
}
public function testGetterAndSetter()
{
$user = new User();

View File

@@ -50,7 +50,28 @@ class UserPreferenceEventTest extends TestCase
$sut = new UserPreferenceEvent($user, []);
$sut->addUserPreference($pref); // change me, once the deprecated method will be deleted
$sut->addPreference($pref);
$sut->addPreference($pref2);
}
/**
* @group legacy
*/
public function testDeprecations()
{
$this->expectException(\InvalidArgumentException::class);
$user = new User();
$user->setAlias('foo');
$pref = new UserPreference();
$pref->setName('foo')->setValue('bar');
$pref2 = new UserPreference();
$pref2->setName('foo')->setValue('hello');
$sut = new UserPreferenceEvent($user, []);
$sut->addUserPreference($pref); // change me, once the deprecated method will be deleted
$sut->addUserPreference($pref2); // change me, once the deprecated method will be deleted
}
}

View File

@@ -32,7 +32,10 @@ class RegistrationSubscriberTest extends TestCase
}
/**
* Legacy test becuase the user bundle won't update to a new release
*
* @dataProvider getTestData
* @group legacy
*/
public function testRoleAssignmentForNewUser(array $existingUsers, $expectedRoles)
{

View File

@@ -25,11 +25,13 @@ abstract class AbstractCalculatorTest extends TestCase
{
protected function assertEmptyModel(CalculatorInterface $sut)
{
$sut->setModel($this->getEmptyModel());
$model = $this->getEmptyModel();
$this->assertEquals('EUR', $model->getCurrency());
$sut->setModel($model);
$this->assertEquals(0, $sut->getTotal());
$this->assertEquals(0, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals(0, $sut->getSubtotal());
$this->assertEquals(0, $sut->getTimeWorked());
$this->assertEquals(0, count($sut->getEntries()));
@@ -89,7 +91,7 @@ abstract class AbstractCalculatorTest extends TestCase
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries([$timesheet]);
$model->addEntries([$timesheet]);
$model->setQuery($query);
$sut->setModel($model);

View File

@@ -136,7 +136,7 @@ class ActivityInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new ActivityInvoiceCalculator();
@@ -145,7 +145,7 @@ class ActivityInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('activity', $sut->getId());
$this->assertEquals(3000.13, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(2521.12, $sut->getSubtotal());
$this->assertEquals(6600, $sut->getTimeWorked());
$this->assertEquals(3, count($sut->getEntries()));

View File

@@ -110,7 +110,7 @@ class DateInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new DateInvoiceCalculator();
@@ -119,7 +119,7 @@ class DateInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('date', $sut->getId());
$this->assertEquals(3000.13, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(2521.12, $sut->getSubtotal());
$this->assertEquals(6600, $sut->getTimeWorked());
$this->assertEquals(3, count($sut->getEntries()));

View File

@@ -61,7 +61,7 @@ class DefaultCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery(new InvoiceQuery());
$sut = new DefaultCalculator();
@@ -70,7 +70,7 @@ class DefaultCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('default', $sut->getId());
$this->assertEquals(581.17, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(488.38, $sut->getSubtotal());
$this->assertEquals(5800, $sut->getTimeWorked());
}

View File

@@ -110,7 +110,7 @@ class ProjectInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new ProjectInvoiceCalculator();
@@ -119,7 +119,7 @@ class ProjectInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('project', $sut->getId());
$this->assertEquals(3000.13, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(2521.12, $sut->getSubtotal());
$this->assertEquals(6600, $sut->getTimeWorked());
$this->assertEquals(3, count($sut->getEntries()));

View File

@@ -90,7 +90,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new ShortInvoiceCalculator();
@@ -99,7 +99,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('short', $sut->getId());
$this->assertEquals(562.28, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(472.5, $sut->getSubtotal());
$this->assertEquals(5800, $sut->getTimeWorked());
$this->assertEquals(1, count($sut->getEntries()));
@@ -171,7 +171,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new ShortInvoiceCalculator();
@@ -180,7 +180,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('short', $sut->getId());
$this->assertEquals(581.17, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(488.38, $sut->getSubtotal());
$this->assertEquals(5800, $sut->getTimeWorked());
$this->assertEquals(1, count($sut->getEntries()));
@@ -250,7 +250,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new ShortInvoiceCalculator();
@@ -259,7 +259,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('short', $sut->getId());
$this->assertEquals(581.17, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(488.38, $sut->getSubtotal());
$this->assertEquals(5400, $sut->getTimeWorked());
$this->assertEquals(1, count($sut->getEntries()));

View File

@@ -108,7 +108,7 @@ class UserInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new UserInvoiceCalculator();
@@ -117,7 +117,7 @@ class UserInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('user', $sut->getId());
$this->assertEquals(3000.13, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(2521.12, $sut->getSubtotal());
$this->assertEquals(6600, $sut->getTimeWorked());
$this->assertEquals(3, count($sut->getEntries()));

View File

@@ -59,10 +59,6 @@ class InvoiceModelTest extends TestCase
self::assertInstanceOf(InvoiceModel::class, $sut->setCalculator($calculator));
self::assertSame($calculator, $sut->getCalculator());
$entries = [new Timesheet()];
self::assertInstanceOf(InvoiceModel::class, $sut->setEntries($entries));
self::assertSame($entries, $sut->getEntries());
$generator = new DateNumberGenerator();
self::assertInstanceOf(InvoiceModel::class, $sut->setNumberGenerator($generator));
self::assertSame($generator, $sut->getNumberGenerator());
@@ -73,4 +69,16 @@ class InvoiceModelTest extends TestCase
self::assertSame($template, $sut->getTemplate());
self::assertInstanceOf(\DateTime::class, $sut->getDueDate());
}
/**
* @group legacy
*/
public function testDeprecations()
{
$sut = new InvoiceModel(new DebugFormatter());
$entries = [new Timesheet()];
self::assertInstanceOf(InvoiceModel::class, $sut->setEntries($entries));
self::assertSame($entries, $sut->getEntries());
}
}

View File

@@ -204,7 +204,7 @@ trait RendererTestTrait
$model = new InvoiceModel($this->getFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$model->setUser($user);
@@ -276,7 +276,7 @@ trait RendererTestTrait
$model = new InvoiceModel($this->getFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$model->setUser($user);

View File

@@ -15,18 +15,23 @@ use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\Client;
/**
* A trait to be used in all tests that extend the KernelTestCase.
*/
trait KernelTestTrait
{
/**
* @param EntityManager $em
* @param Fixture $fixture
*/
protected function importFixture(EntityManager $em, Fixture $fixture)
protected function importFixture($client, Fixture $fixture)
{
if ($client instanceof Client) {
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
} elseif ($client instanceof EntityManager) {
$em = $client;
} else {
throw new \InvalidArgumentException('Fixtures need an EntityManager to be imported');
}
$loader = new Loader();
$loader->addFixture($fixture);

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\Type\Counter;
use App\Widget\WidgetException;
use PHPUnit\Framework\TestCase;
@@ -87,6 +88,7 @@ class WidgetRepositoryTest extends TestCase
'end' => null,
'query' => $query,
'title' => 'Test widget',
'type' => Counter::class,
];
$sut = new WidgetRepository($repoMock, $userMock, ['test' => $widget]);