setAmount($amount); if (\is_array($status)) { $fixture->setStatus($status); } return $this->importFixture($fixture); } public function testIsSecure(): void { $this->assertUrlIsSecured('/api/invoices'); } public function testGetCollection(): void { $client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD); $this->importInvoiceFixtures(10); $this->assertAccessIsGranted($client, '/api/invoices'); $content = $client->getResponse()->getContent(); $this->assertIsString($content); $result = json_decode($content, true); $this->assertIsArray($result); $this->assertNotEmpty($result); $this->assertEquals(10, \count($result)); self::assertApiResponseTypeStructure('InvoiceCollection', $result[0]); } public function testGetCollectionWithQuery(): void { $client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD); $this->importInvoiceFixtures(5, [Invoice::STATUS_PENDING]); $this->importInvoiceFixtures(2, [Invoice::STATUS_NEW]); $this->importInvoiceFixtures(7, [Invoice::STATUS_PAID]); $this->importInvoiceFixtures(1, [Invoice::STATUS_CANCELED]); $query = ['order' => 'ASC', 'orderBy' => 'name', 'status' => [Invoice::STATUS_PAID]]; $this->assertAccessIsGranted($client, '/api/invoices', 'GET', $query); $content = $client->getResponse()->getContent(); $this->assertIsString($content); $result = json_decode($content, true); $this->assertIsArray($result); $this->assertNotEmpty($result); $this->assertEquals(7, \count($result)); self::assertApiResponseTypeStructure('InvoiceCollection', $result[0]); } public function testGetEntityIsSecure(): void { $client = $this->getClientForAuthenticatedUser(); $invoices = $this->importInvoiceFixtures(1); $this->assertApiAccessDenied($client, '/api/invoices/' . $invoices[0]->getId()); } public function testGetEntity(): void { $client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN); $invoices = $this->importInvoiceFixtures(1); $this->assertAccessIsGranted($client, '/api/invoices/' . $invoices[0]->getId()); $content = $client->getResponse()->getContent(); $this->assertIsString($content); $result = json_decode($content, true); $this->assertIsArray($result); self::assertApiResponseTypeStructure('Invoice', $result); } public function testNotFound(): void { $this->assertEntityNotFound(User::ROLE_USER, '/api/invoices/' . PHP_INT_MAX); } }