Skip to content

Commit

Permalink
Merge pull request #33 from fr3nch13/2.x-dev
Browse files Browse the repository at this point in the history
Test updates
  • Loading branch information
fr3nch13 committed Apr 13, 2022
2 parents 8daacce + 4ffa4ff commit 1f69d1b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 127 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.3",
"php": "^7.4",
"cakephp/bake": "^2.3",
"cakephp/cakephp": "~4.0",
"cakephp/cakephp-codesniffer": "~4.2",
Expand Down Expand Up @@ -55,9 +55,9 @@
"@coverage-text"
],
"check": [
"@test",
"@cs-check",
"@phpstan",
"@test"
"@phpstan"
],
"fix": [
"@cs-fix",
Expand Down
54 changes: 20 additions & 34 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
processIsolation="true"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage>
<include>
<directory suffix=".php">./src/</directory>
</include>
</coverage>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>
<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="Fr3nch13\Pta">
<directory>./tests/TestCase/</directory>
</testsuite>
</testsuites>
<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="\Cake\TestSuite\Fixture\FixtureInjector"
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php"
>
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager"/>
</arguments>
</listener>
</listeners>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" processIsolation="false" stopOnFailure="false" bootstrap="./tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src/</directory>
<directory suffix=".ctp">./src/</directory>
</include>
</coverage>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>
<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="Fr3nch13\Pta">
<directory>./tests/TestCase/</directory>
</testsuite>
</testsuites>
<extensions>
<extension class="\Cake\TestSuite\Fixture\PHPUnitExtension" />
</extensions>
</phpunit>
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function bootstrap(\Cake\Core\PluginApplicationInterface $app): void
public function routes(\Cake\Routing\RouteBuilder $routes): void
{
// Add routes.
Router::plugin(
$routes->plugin(
'Fr3nch13/Pta',
['path' => '/pta'],
function (\Cake\Routing\RouteBuilder $routes) {
Expand Down
Empty file removed tests/Fixture/empty
Empty file.
8 changes: 1 addition & 7 deletions tests/TestCase/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ public function testBootstrap()
*/
public function testRoutes()
{
$app = new Application(CONFIG);
$app->bootstrap();
$app->pluginBootstrap();
$collection = new RouteCollection();
$routeBuilder = new RouteBuilder($collection, '');
$app->pluginRoutes($routeBuilder);
$plugins = $app->getPlugins();
$this->loadPlugins(['Fr3nch13/Pta']);

$url = Router::url(['plugin' => 'Fr3nch13/Pta', 'controller' => 'App']);

Expand Down
97 changes: 15 additions & 82 deletions tests/test_app/config/routes.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
declare(strict_types=1);

/**
* Routes configuration
Expand All @@ -19,88 +18,22 @@
* @link https://cakephp.org CakePHP(tm) Project
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

use Cake\Http\Middleware\CsrfProtectionMiddleware;
use Cake\Routing\Route\DashedRoute;
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;

/**
* The default class to use for all routes
*
* The following route classes are supplied with CakePHP and are appropriate
* to set as the default:
*
* - Route
* - InflectedRoute
* - DashedRoute
*
* If no call is made to `Router::defaultRouteClass()`, the class used is
* `Route` (`Cake\Routing\Route\Route`)
*
* Note that `Route` does not do any inflections on URLs which will result in
* inconsistently cased URLs when used with `:plugin`, `:controller` and
* `:action` markers.
*
* Cache: Routes are cached to improve performance, check the RoutingMiddleware
* constructor in your `src/Application.php` file to change this behavior.
*/
Router::defaultRouteClass(\Cake\Routing\Route\DashedRoute::class);

Router::scope('/', function (\Cake\Routing\RouteBuilder $routes) {
// Register scoped middleware for in scopes.
$routes->registerMiddleware('csrf', new CsrfProtectionMiddleware([
'httpOnly' => true,
]));

/**
* Apply a middleware to the current route scope.
* Requires middleware to be registered via `Application::routes()` with `registerMiddleware()`
*/
$routes->applyMiddleware('csrf');

/**
* Here, we are connecting '/' (base path) to a controller called 'Pages',
* its action called 'display', and we pass a param to select the view file
* to use (in this case, src/Template/Pages/home.ctp)...
*/
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);

/**
* ...and connect the rest of 'Pages' controller's URLs.
*/
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);

/**
* Connect catchall routes for all controllers.
*
* Using the argument `DashedRoute`, the `fallbacks` method is a shortcut for
*
* ```
* $routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'DashedRoute']);
* $routes->connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']);
* ```
*
* Any route class can be used with this method, such as:
* - DashedRoute
* - InflectedRoute
* - Route
* - Or your own route class
*
* You can remove these routes once you've connected the
* routes you want in your application.
*/
$routes->fallbacks(\Cake\Routing\Route\DashedRoute::class);
});

/**
* If you need a different set of middleware or none at all,
* open new scope and define routes there.
*
* ```
* Router::scope('/api', function (\Cake\Routing\RouteBuilder $routes) {
* // No $routes->applyMiddleware() here.
* // Connect API actions here.
* });
* ```
*/
return static function (RouteBuilder $routes) {
$routes->setRouteClass(DashedRoute::class);

$routes->scope('/', function (RouteBuilder $routes) {
$routes->setExtensions(['json', 'm', 'xml', 'txt', 'csv', 'pdf', 'xlsx']);
$routes->registerMiddleware('csrf', new CsrfProtectionMiddleware([
'httponly' => true,
]));
$routes->applyMiddleware('csrf');
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);

$routes->fallbacks(\Cake\Routing\Route\DashedRoute::class);
});
};
Empty file.

0 comments on commit 1f69d1b

Please sign in to comment.