Release 2.35 (#5470)
* open up API for plugins by removing internal * use constants in entity column definition * simplified entity management API * bump packages * allow installing assets and run database migrations independently * bump to apidoc-bundle 5 * do not duplicate http method in API operationId * new security entries in Open API definition * changed API UI provider for Swagger to Stoplight, improved endpoint titles, hide internal endpoints * deactivate swagger json endpoint
This commit is contained in:
@@ -26,11 +26,21 @@ class ApiDocControllerTest extends AbstractControllerBaseTestCase
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/doc');
|
||||
self::assertStringContainsString('<title>Kimai', $client->getResponse()->getContent());
|
||||
$result = $client->getCrawler()->filter('script#swagger-data');
|
||||
$swaggerJson = json_decode($result->text(), true);
|
||||
$content = $client->getResponse()->getContent();
|
||||
self::assertIsString($content);
|
||||
self::assertStringContainsString('<title>Kimai', $content);
|
||||
self::assertStringContainsString('docs.apiDescriptionDocument', $content);
|
||||
self::assertStringContainsString('const config = {"basePath":"/api/doc","router":"memory","logo":"/touch-icon-192x192.png","hideInternal":true};', $content);
|
||||
$results = preg_match('/docs\.apiDescriptionDocument\ \=\ (.*)\.spec;/', $content, $matches);
|
||||
self::assertNotFalse($results);
|
||||
$swaggerJson = json_decode($matches[1], true);
|
||||
self::assertIsArray($swaggerJson);
|
||||
self::assertArrayHasKey('spec', $swaggerJson);
|
||||
$json = $swaggerJson['spec'];
|
||||
self::assertArrayHasKey('paths', $json);
|
||||
|
||||
$tags = [];
|
||||
foreach ($swaggerJson['spec']['paths'] as $path) {
|
||||
foreach ($json['paths'] as $path) {
|
||||
foreach ($path as $method) {
|
||||
foreach ($method['tags'] as $tag) {
|
||||
$tags[$tag] = $tag;
|
||||
@@ -45,13 +55,6 @@ class ApiDocControllerTest extends AbstractControllerBaseTestCase
|
||||
sort($expectedKeys);
|
||||
|
||||
self::assertEquals($expectedKeys, $actual, \sprintf('Expected %s sections in API docs, but found %s.', \count($actual), \count($expectedKeys)));
|
||||
}
|
||||
|
||||
public function testGetJsonDocs(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/doc.json');
|
||||
$json = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$paths = [
|
||||
'/api/actions/timesheet/{id}/{view}/{locale}',
|
||||
@@ -108,7 +111,7 @@ class ApiDocControllerTest extends AbstractControllerBaseTestCase
|
||||
self::assertEquals('3.0.0', $json['openapi']);
|
||||
self::assertArrayHasKey('info', $json);
|
||||
self::assertStringStartsWith('Kimai', $json['info']['title']);
|
||||
self::assertEquals('1.0', $json['info']['version']);
|
||||
self::assertEquals('1.1', $json['info']['version']);
|
||||
|
||||
self::assertArrayHasKey('paths', $json);
|
||||
self::assertEquals($paths, array_keys($json['paths']));
|
||||
@@ -119,10 +122,6 @@ class ApiDocControllerTest extends AbstractControllerBaseTestCase
|
||||
self::assertArrayHasKey('components', $json);
|
||||
self::assertArrayHasKey('schemas', $json['components']);
|
||||
self::assertArrayHasKey('securitySchemes', $json['components']);
|
||||
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
self::assertIsArray($result);
|
||||
self::assertNotEmpty($result);
|
||||
}
|
||||
|
||||
protected function createUrl(string $url): string
|
||||
|
||||
@@ -58,19 +58,6 @@ class ActivityServiceTest extends TestCase
|
||||
return $service;
|
||||
}
|
||||
|
||||
public function testCannotSavePersistedProjectAsNew(): void
|
||||
{
|
||||
$project = $this->createMock(Activity::class);
|
||||
$project->expects($this->once())->method('getId')->willReturn(1);
|
||||
|
||||
$sut = $this->getSut();
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Cannot create activity, already persisted');
|
||||
|
||||
$sut->saveNewActivity($project);
|
||||
}
|
||||
|
||||
public function testsaveNewActivityHasValidationError(): void
|
||||
{
|
||||
$constraints = new ConstraintViolationList();
|
||||
@@ -84,7 +71,7 @@ class ActivityServiceTest extends TestCase
|
||||
$this->expectException(ValidationFailedException::class);
|
||||
$this->expectExceptionMessage('Validation Failed');
|
||||
|
||||
$sut->saveNewActivity(new Activity());
|
||||
$sut->saveActivity(new Activity());
|
||||
}
|
||||
|
||||
public function testUpdateDispatchesEvents(): void
|
||||
@@ -107,7 +94,7 @@ class ActivityServiceTest extends TestCase
|
||||
|
||||
$sut = $this->getSut($dispatcher);
|
||||
|
||||
$sut->updateActivity($project);
|
||||
$sut->saveActivity($project);
|
||||
}
|
||||
|
||||
public function testcreateNewActivityDispatchesEvents(): void
|
||||
@@ -143,7 +130,7 @@ class ActivityServiceTest extends TestCase
|
||||
$sut = $this->getSut($dispatcher);
|
||||
|
||||
$activity = new Activity();
|
||||
$sut->saveNewActivity($activity);
|
||||
$sut->saveActivity($activity);
|
||||
}
|
||||
|
||||
public function testcreateNewActivityWithoutCustomer(): void
|
||||
|
||||
@@ -16,7 +16,6 @@ use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\LogicException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
@@ -62,17 +61,6 @@ class BundleInstallerCommandTest extends KernelTestCase
|
||||
self::assertEquals(1, $commandTester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testAssetsInstallationFailure(): void
|
||||
{
|
||||
$command = $this->getCommand(AssetsInstallerFailureCommand::class);
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(['command' => $command->getName()]);
|
||||
$result = $commandTester->getDisplay();
|
||||
|
||||
self::assertStringContainsString('[ERROR] Failed to install assets for bundle TestBundle.', $result);
|
||||
self::assertEquals(1, $commandTester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testInvalidNamespaceWillRaiseException(): void
|
||||
{
|
||||
$this->expectException(LogicException::class);
|
||||
@@ -162,19 +150,6 @@ class InstallerWithMissingMigrationsCommand extends TestBundleInstallerCommand
|
||||
}
|
||||
}
|
||||
|
||||
class AssetsInstallerFailureCommand extends TestBundleInstallerCommand
|
||||
{
|
||||
protected function hasAssets(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function installAssets(SymfonyStyle $io, OutputInterface $output): void
|
||||
{
|
||||
throw new \Exception('Problem occurred while installing assets.');
|
||||
}
|
||||
}
|
||||
|
||||
class InstallerWithAssetsCommand extends TestBundleInstallerCommand
|
||||
{
|
||||
protected function hasAssets(): bool
|
||||
|
||||
@@ -69,19 +69,6 @@ class CustomerServiceTest extends TestCase
|
||||
return new CustomerService($repository, $configuration, $validator, $dispatcher);
|
||||
}
|
||||
|
||||
public function testCannotSavePersistedCustomerAsNew(): void
|
||||
{
|
||||
$Customer = $this->createMock(Customer::class);
|
||||
$Customer->expects($this->once())->method('getId')->willReturn(1);
|
||||
|
||||
$sut = $this->getSut();
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Cannot create customer, already persisted');
|
||||
|
||||
$sut->saveNewCustomer($Customer);
|
||||
}
|
||||
|
||||
public function testSaveNewCustomerHasValidationError(): void
|
||||
{
|
||||
$constraints = new ConstraintViolationList();
|
||||
@@ -95,7 +82,7 @@ class CustomerServiceTest extends TestCase
|
||||
$this->expectException(ValidationFailedException::class);
|
||||
$this->expectExceptionMessage('Validation Failed');
|
||||
|
||||
$sut->saveNewCustomer(new Customer('foo'));
|
||||
$sut->saveCustomer(new Customer('foo'));
|
||||
}
|
||||
|
||||
public function testUpdateDispatchesEvents(): void
|
||||
@@ -118,7 +105,7 @@ class CustomerServiceTest extends TestCase
|
||||
|
||||
$sut = $this->getSut($dispatcher);
|
||||
|
||||
$sut->updateCustomer($Customer);
|
||||
$sut->saveCustomer($Customer);
|
||||
}
|
||||
|
||||
public function testCreateNewCustomerDispatchesEvents(): void
|
||||
@@ -155,7 +142,7 @@ class CustomerServiceTest extends TestCase
|
||||
$sut = $this->getSut($dispatcher);
|
||||
|
||||
$Customer = new Customer('foo');
|
||||
$sut->saveNewCustomer($Customer);
|
||||
$sut->saveCustomer($Customer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,19 +64,6 @@ class ProjectServiceTest extends TestCase
|
||||
return new ProjectService($repository, $configuration, $dispatcher, $validator);
|
||||
}
|
||||
|
||||
public function testCannotSavePersistedProjectAsNew(): void
|
||||
{
|
||||
$project = $this->createMock(Project::class);
|
||||
$project->expects($this->once())->method('getId')->willReturn(1);
|
||||
|
||||
$sut = $this->getSut();
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Cannot create project, already persisted');
|
||||
|
||||
$sut->saveNewProject($project, new Context(new User()));
|
||||
}
|
||||
|
||||
public function testSaveNewProjectHasValidationError(): void
|
||||
{
|
||||
$constraints = new ConstraintViolationList();
|
||||
@@ -90,7 +77,7 @@ class ProjectServiceTest extends TestCase
|
||||
$this->expectException(ValidationFailedException::class);
|
||||
$this->expectExceptionMessage('Validation Failed');
|
||||
|
||||
$sut->saveNewProject(new Project(), new Context(new User()));
|
||||
$sut->saveProject(new Project(), new Context(new User()));
|
||||
}
|
||||
|
||||
public function testUpdateDispatchesEvents(): void
|
||||
@@ -113,7 +100,7 @@ class ProjectServiceTest extends TestCase
|
||||
|
||||
$sut = $this->getSut($dispatcher);
|
||||
|
||||
$sut->updateProject($project);
|
||||
$sut->saveProject($project);
|
||||
}
|
||||
|
||||
public function testCreateNewProjectDispatchesEvents(): void
|
||||
@@ -149,7 +136,7 @@ class ProjectServiceTest extends TestCase
|
||||
$sut = $this->getSut($dispatcher);
|
||||
|
||||
$project = new Project();
|
||||
$sut->saveNewProject($project, new Context(new User()));
|
||||
$sut->saveProject($project, new Context(new User()));
|
||||
self::assertCount(0, $project->getTeams());
|
||||
}
|
||||
|
||||
@@ -170,7 +157,7 @@ class ProjectServiceTest extends TestCase
|
||||
$user->addTeam($team2);
|
||||
|
||||
$project = new Project();
|
||||
$sut->saveNewProject($project, new Context($user));
|
||||
$sut->saveProject($project, new Context($user));
|
||||
self::assertCount(2, $project->getTeams());
|
||||
}
|
||||
|
||||
|
||||
@@ -187,41 +187,6 @@ parameters:
|
||||
count: 13
|
||||
path: API/ActivityControllerTest.php
|
||||
|
||||
-
|
||||
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
|
||||
count: 3
|
||||
path: API/ApiDocControllerTest.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access offset 'paths' on mixed\\.$#"
|
||||
count: 1
|
||||
path: API/ApiDocControllerTest.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access offset 'spec' on mixed\\.$#"
|
||||
count: 1
|
||||
path: API/ApiDocControllerTest.php
|
||||
|
||||
-
|
||||
message: "#^Cannot access offset 'tags' on mixed\\.$#"
|
||||
count: 1
|
||||
path: API/ApiDocControllerTest.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#"
|
||||
count: 2
|
||||
path: API/ApiDocControllerTest.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$array of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) expects array\\|ArrayAccess, mixed given\\.$#"
|
||||
count: 1
|
||||
path: API/ApiDocControllerTest.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$haystack of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\) expects string, string\\|false given\\.$#"
|
||||
count: 1
|
||||
path: API/ApiDocControllerTest.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method getValue\\(\\) on App\\\\Entity\\\\MetaTableTypeInterface\\|null\\.$#"
|
||||
count: 1
|
||||
|
||||
Reference in New Issue
Block a user