Skip to content
Snippets Groups Projects
Commit 2224026f authored by Tobias Gross-Vogt's avatar Tobias Gross-Vogt
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #85964 passed
services:
Dbp\Relay\CourseBundle\Command\TestCommand:
autowire: true
autoconfigure: true
Dbp\Relay\CourseBundle\Controller\:
resource: '../../Controller'
autoconfigure: true
autowire: true
Dbp\Relay\CourseBundle\DataPersister\:
resource: '../../DataPersister'
autowire: true
autoconfigure: true
Dbp\Relay\CourseBundle\DataProvider\:
resource: '../../DataProvider'
autowire: true
autoconfigure: true
Dbp\Relay\CourseBundle\Service\ExternalApi:
autowire: true
autoconfigure: true
Dbp\Relay\CourseBundle\Service\MyCustomService:
autowire: true
autoconfigure: true
Dbp\Relay\CourseBundle\Service\CourseProviderInterface:
'@Dbp\Relay\CourseBundle\Service\ExternalApi'
<?php
declare(strict_types=1);
namespace Dbp\Relay\CourseBundle\Service;
use Dbp\Relay\CourseBundle\Entity\Course;
interface CourseProviderInterface
{
public function getCourseById(string $identifier): ?Course;
public function getCourses(): array;
}
<?php
declare(strict_types=1);
namespace Dbp\Relay\CourseBundle\Service;
use Dbp\Relay\CourseBundle\Entity\Course;
class ExternalApi implements CourseProviderInterface
{
private $courses;
public function __construct(MyCustomService $service)
{
// Make phpstan happy
$service = $service;
$this->courses = [];
$course1 = new Course();
$course1->setIdentifier('graz');
$course1->setName('Graz');
$course2 = new Course();
$course2->setIdentifier('vienna');
$course2->setName('Vienna');
$this->courses[] = $course1;
$this->courses[] = $course2;
}
public function getCourseById(string $identifier): ?Course
{
foreach ($this->courses as $course) {
if ($course->getIdentifier() === $identifier) {
return $course;
}
}
return null;
}
public function getCourses(): array
{
return $this->courses;
}
}
<?php
declare(strict_types=1);
namespace Dbp\Relay\CourseBundle\Service;
class MyCustomService
{
private $someConfig;
public function __construct(string $someConfig)
{
$this->$someConfig = $someConfig;
}
}
<?php
declare(strict_types=1);
namespace Dbp\Relay\CourseBundle\Tests;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
use Symfony\Component\HttpFoundation\Response;
class ApiTest extends ApiTestCase
{
public function testBasics()
{
$client = self::createClient();
$response = $client->request('GET', '/course/courses');
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
$response = $client->request('GET', '/course/courses/graz');
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
$response = $client->request('DELETE', '/course/courses/graz');
$this->assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode());
$response = $client->request('PUT', '/course/courses/graz', [
'headers' => [
'Content-Type' => 'application/json',
],
'body' => json_encode(['name' => 'foo']),
]);
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
$this->assertSame('foo', json_decode($response->getContent(), true)['name']);
}
public function testNoAuth()
{
$client = self::createClient();
$response = $client->request('GET', '/course/courses/graz/loggedin-only');
$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());
}
}
<?php
declare(strict_types=1);
namespace Dbp\Relay\CourseBundle\Tests;
use ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle;
use Dbp\Relay\CoreBundle\DbpRelayCoreBundle;
use Dbp\Relay\CourseBundle\DbpRelayCourseBundle;
use Nelmio\CorsBundle\NelmioCorsBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\MonologBundle\MonologBundle;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
class Kernel extends BaseKernel
{
use MicroKernelTrait;
public function registerBundles(): iterable
{
yield new FrameworkBundle();
yield new SecurityBundle();
yield new TwigBundle();
yield new NelmioCorsBundle();
yield new MonologBundle();
yield new ApiPlatformBundle();
yield new DbpRelayCourseBundle();
yield new DbpRelayCoreBundle();
}
protected function configureRoutes(RouteCollectionBuilder $routes)
{
$routes->import('@DbpRelayCoreBundle/Resources/config/routing.yaml');
}
protected function configureContainer(ContainerConfigurator $container, LoaderInterface $loader)
{
$container->import('@DbpRelayCoreBundle/Resources/config/services_test.yaml');
$container->extension('framework', [
'test' => true,
'secret' => '',
]);
$container->extension('dbp_relay_course', [
'example_config' => 'test-42',
]);
}
}
<?php
declare(strict_types=1);
namespace Dbp\Relay\CourseBundle\Tests\Service;
use Dbp\Relay\CourseBundle\Service\ExternalApi;
use Dbp\Relay\CourseBundle\Service\MyCustomService;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ExternalApiTest extends WebTestCase
{
private $api;
protected function setUp(): void
{
$service = new MyCustomService('test-42');
$this->api = new ExternalApi($service);
}
public function test()
{
$this->assertTrue(true);
$this->assertNotNull($this->api);
}
}
<?php
declare(strict_types=1);
require dirname(__DIR__).'/vendor/autoload.php';
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment