Skip to content

Commit b8f83a3

Browse files
committed
improve tests, replace psr7 implementation
1 parent 53ea496 commit b8f83a3

File tree

14 files changed

+191
-149
lines changed

14 files changed

+191
-149
lines changed

Bootstraps/Symfony.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPPM\Bootstraps;
44

5+
use PHPPM\ProcessSlave;
56
use PHPPM\Symfony\StrongerNativeSessionStorage;
67
use PHPPM\Utils;
78
use Symfony\Component\HttpFoundation\Request;
@@ -88,7 +89,7 @@ public function getApplication()
8889
$app->booted = true;
8990
}, $app);
9091

91-
if ($this->debug) {
92+
if ($this->debug && ProcessSlave::$slave) {
9293
Utils::bindAndCall(function () use ($app) {
9394
$container = $app->container;
9495

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": {
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\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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace PHPPM\Tests\Fixtures\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+
return new Response('Received JSON: '.$request->getContent(), 201);
22+
}
23+
}
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\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\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/Kernel.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace PHPPM\Tests\Fixtures;
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 . '/{packages}/*' . self::CONFIG_EXTS, 'glob');
37+
$loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
38+
$loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob');
39+
$loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob');
40+
}
41+
42+
protected function configureRoutes(RouteCollectionBuilder $routes)
43+
{
44+
$confDir = $this->getProjectDir() . '/config';
45+
46+
$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob');
47+
$routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob');
48+
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
49+
}
50+
51+
public function getProjectDir()
52+
{
53+
return __DIR__;
54+
}
55+
}

tests/Fixtures/config/bundles.php

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+
];

tests/Fixtures/config/routes.yaml

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)