-
Notifications
You must be signed in to change notification settings - Fork 71
Improve tests, replace psr7 implementation #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,14 @@ | |
"license": "MIT", | ||
"require": { | ||
"php-pm/php-pm": "^1.0.5", | ||
"symfony/http-foundation": "^2.6|^3.0|^4", | ||
"symfony/http-kernel": "^2.6|^3.0|^4", | ||
"ringcentral/psr7": "^1.2" | ||
"symfony/http-foundation": "^3.4|^4", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dropped 2.X already There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think- can we release this in a point release? Effectively we're dropping support for Symfony before 3.4? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The proposed 'kernel.reset' interface for Symfony is only in 3.4+. Also, SF 2.x is EOL already, I'd say it's time to move on. |
||
"symfony/http-kernel": "^3.4|^4", | ||
"guzzlehttp/psr7": "^1.5" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.7" | ||
"phpunit/phpunit": "^5.7", | ||
"symfony/framework-bundle": "^3.4|^4", | ||
"doctrine/annotations": "^1.6" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to require the annotations here or aren't they implicit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nopes, they aren't implicit, Symfony relies on them for routing annotation but you need to import the library yourself |
||
}, | ||
"autoload": { | ||
"psr-4": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace PHPPM\Tests\Fixtures; | ||
|
||
class ProcessSlaveDouble | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used to have support for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will be useful when creating a test that checks if a symfony container resource is actually being added to the list of watched files |
||
{ | ||
private $watchedFiles = []; | ||
|
||
public function registerFile($file) | ||
{ | ||
$this->watchedFiles[] = $file; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace PHPPM\Tests\Fixtures\Symfony\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class GetController extends Controller | ||
{ | ||
/** | ||
* @Route("/get") | ||
*/ | ||
public function __invoke() | ||
{ | ||
return new Response('Success', 200); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace PHPPM\Tests\Fixtures\Symfony\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class PostJsonController extends Controller | ||
{ | ||
/** | ||
* @Route("/json", methods={"POST"}) | ||
*/ | ||
public function __invoke(Request $request) | ||
{ | ||
$body = json_decode($request->getContent(), true); | ||
if ($request->getContent() == null || !$body) { | ||
throw new \Exception('Invalid JSON body'); | ||
} | ||
|
||
return new Response('Received JSON: '.$request->getContent(), 201); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace PHPPM\Tests\Fixtures\Symfony\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\StreamedResponse; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class StreamedController extends Controller | ||
{ | ||
/** | ||
* @Route("/streamed") | ||
*/ | ||
public function __invoke() | ||
{ | ||
return new StreamedResponse(function () { | ||
echo 'streamed data'; | ||
}, 200); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace PHPPM\Tests\Fixtures\Symfony\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class UploadController extends Controller | ||
{ | ||
/** | ||
* @Route("/upload", methods={"POST"}) | ||
*/ | ||
public function __invoke(Request $request) | ||
{ | ||
$mappedFileNames = array_map(function ($f) { | ||
if (!isset($f)) { | ||
return 'NULL'; | ||
} | ||
return $f->getClientOriginalName(); | ||
}, $request->files->all()); | ||
|
||
return new Response('Uploaded files: '.implode(',', $mappedFileNames), 201); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace PHPPM\Tests\Fixtures\Symfony; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\Config\Resource\FileResource; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\Routing\RouteCollectionBuilder; | ||
|
||
class Kernel extends \Symfony\Component\HttpKernel\Kernel | ||
{ | ||
use MicroKernelTrait; | ||
|
||
const CONFIG_EXTS = '.{php,xml,yaml,yml}'; | ||
|
||
public function registerBundles() | ||
{ | ||
$contents = require $this->getProjectDir() . '/config/bundles.php'; | ||
foreach ($contents as $class => $envs) { | ||
if (isset($envs['all']) || isset($envs[$this->environment])) { | ||
yield new $class(); | ||
} | ||
} | ||
} | ||
|
||
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) | ||
{ | ||
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php')); | ||
// Feel free to remove the "container.autowiring.strict_mode" parameter | ||
// if you are using symfony/dependency-injection 4.0+ as it's the default behavior | ||
$container->setParameter('container.autowiring.strict_mode', true); | ||
$container->setParameter('container.dumper.inline_class_loader', true); | ||
$confDir = $this->getProjectDir() . '/config'; | ||
|
||
$loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob'); | ||
} | ||
|
||
protected function configureRoutes(RouteCollectionBuilder $routes) | ||
{ | ||
$confDir = $this->getProjectDir() . '/config'; | ||
|
||
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob'); | ||
} | ||
|
||
public function getProjectDir() | ||
{ | ||
return __DIR__; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
controllers: | ||
resource: '../Controller/' | ||
type: annotation |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
services: | ||
framework: | ||
secret: foobar |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that's not really needed here but it reduces the number of dependencies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a change to a more complete PSR7 implementation and to a better maintained library, it doesn't really change the number of dependencies itself.
Also, the Psr7 Response object is used here. Are you refering to something else?