Skip to content

Commit 6210935

Browse files
acasademontandig
authored andcommitted
improve tests, replace psr7 implementation (#152)
1 parent 53ea496 commit 6210935

File tree

14 files changed

+205
-148
lines changed

14 files changed

+205
-148
lines changed

Bridges/HttpKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Psr\Http\Message\ServerRequestInterface;
1010
use Psr\Http\Message\ResponseInterface;
1111
use Psr\Http\Message\UploadedFileInterface;
12-
use RingCentral\Psr7;
12+
use GuzzleHttp\Psr7;
1313
use Symfony\Component\HttpFoundation\Cookie;
1414
use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyFile;
1515
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
"license": "MIT",
44
"require": {
55
"php-pm/php-pm": "^1.0.5",
6-
"symfony/http-foundation": "^2.6|^3.0|^4",
7-
"symfony/http-kernel": "^2.6|^3.0|^4",
8-
"ringcentral/psr7": "^1.2"
6+
"symfony/http-foundation": "^3.4|^4",
7+
"symfony/http-kernel": "^3.4|^4",
8+
"guzzlehttp/psr7": "^1.5"
99
},
1010
"require-dev": {
11-
"phpunit/phpunit": "^5.7"
11+
"phpunit/phpunit": "^5.7",
12+
"symfony/framework-bundle": "^3.4|^4",
13+
"doctrine/annotations": "^1.6"
1214
},
1315
"autoload": {
1416
"psr-4": {

tests/Fixtures/ProcessSlaveDouble.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace PHPPM\Tests\Fixtures;
4+
5+
class ProcessSlaveDouble
6+
{
7+
private $watchedFiles = [];
8+
9+
public function registerFile($file)
10+
{
11+
$this->watchedFiles[] = $file;
12+
}
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace PHPPM\Tests\Fixtures\Symfony\Controller;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\HttpFoundation\Response;
7+
use Symfony\Component\Routing\Annotation\Route;
8+
9+
class GetController extends Controller
10+
{
11+
/**
12+
* @Route("/get")
13+
*/
14+
public function __invoke()
15+
{
16+
return new Response('Success', 200);
17+
}
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace PHPPM\Tests\Fixtures\Symfony\Controller;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\HttpFoundation\Request;
7+
use Symfony\Component\HttpFoundation\Response;
8+
use Symfony\Component\Routing\Annotation\Route;
9+
10+
class PostJsonController extends Controller
11+
{
12+
/**
13+
* @Route("/json", methods={"POST"})
14+
*/
15+
public function __invoke(Request $request)
16+
{
17+
$body = json_decode($request->getContent(), true);
18+
if ($request->getContent() == null || !$body) {
19+
throw new \Exception('Invalid JSON body');
20+
}
21+
22+
return new Response('Received JSON: '.$request->getContent(), 201);
23+
}
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace PHPPM\Tests\Fixtures\Symfony\Controller;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\HttpFoundation\StreamedResponse;
7+
use Symfony\Component\Routing\Annotation\Route;
8+
9+
class StreamedController extends Controller
10+
{
11+
/**
12+
* @Route("/streamed")
13+
*/
14+
public function __invoke()
15+
{
16+
return new StreamedResponse(function () {
17+
echo 'streamed data';
18+
}, 200);
19+
}
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace PHPPM\Tests\Fixtures\Symfony\Controller;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\HttpFoundation\Request;
7+
use Symfony\Component\HttpFoundation\Response;
8+
use Symfony\Component\Routing\Annotation\Route;
9+
10+
class UploadController extends Controller
11+
{
12+
/**
13+
* @Route("/upload", methods={"POST"})
14+
*/
15+
public function __invoke(Request $request)
16+
{
17+
$mappedFileNames = array_map(function ($f) {
18+
if (!isset($f)) {
19+
return 'NULL';
20+
}
21+
return $f->getClientOriginalName();
22+
}, $request->files->all());
23+
24+
return new Response('Uploaded files: '.implode(',', $mappedFileNames), 201);
25+
}
26+
}

tests/Fixtures/Symfony/Kernel.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace PHPPM\Tests\Fixtures\Symfony;
4+
5+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
6+
use Symfony\Component\Config\Loader\LoaderInterface;
7+
use Symfony\Component\Config\Resource\FileResource;
8+
use Symfony\Component\DependencyInjection\ContainerBuilder;
9+
use Symfony\Component\Routing\RouteCollectionBuilder;
10+
11+
class Kernel extends \Symfony\Component\HttpKernel\Kernel
12+
{
13+
use MicroKernelTrait;
14+
15+
const CONFIG_EXTS = '.{php,xml,yaml,yml}';
16+
17+
public function registerBundles()
18+
{
19+
$contents = require $this->getProjectDir() . '/config/bundles.php';
20+
foreach ($contents as $class => $envs) {
21+
if (isset($envs['all']) || isset($envs[$this->environment])) {
22+
yield new $class();
23+
}
24+
}
25+
}
26+
27+
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
28+
{
29+
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
30+
// Feel free to remove the "container.autowiring.strict_mode" parameter
31+
// if you are using symfony/dependency-injection 4.0+ as it's the default behavior
32+
$container->setParameter('container.autowiring.strict_mode', true);
33+
$container->setParameter('container.dumper.inline_class_loader', true);
34+
$confDir = $this->getProjectDir() . '/config';
35+
36+
$loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob');
37+
}
38+
39+
protected function configureRoutes(RouteCollectionBuilder $routes)
40+
{
41+
$confDir = $this->getProjectDir() . '/config';
42+
43+
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
44+
}
45+
46+
public function getProjectDir()
47+
{
48+
return __DIR__;
49+
}
50+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
5+
];
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
controllers:
2+
resource: '../Controller/'
3+
type: annotation

0 commit comments

Comments
 (0)