Skip to content

Commit

Permalink
more test cs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Apr 6, 2024
1 parent cc4d043 commit 1d971a6
Show file tree
Hide file tree
Showing 25 changed files with 160 additions and 323 deletions.
19 changes: 3 additions & 16 deletions tests/Functional/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,12 @@

class BaseTestCase extends ComponentBaseTestCase
{
/**
* @return DocumentManagerInterface
*/
protected function getDm()
protected function getDm(): DocumentManagerInterface
{
return $this->db('PHPCR')->getOm();
}

/**
* @param string $path
*
* @return Route
*/
protected function createRoute($path)
protected function createRoute(string $path): Route
{
$parentPath = PathHelper::getParentPath($path);
$parent = $this->getDm()->find(null, $parentPath);
Expand All @@ -45,12 +37,7 @@ protected function createRoute($path)
return $route;
}

/**
* @param string $path
*
* @return Content
*/
protected function createContent($path = '/test/content')
protected function createContent(string $path = '/test/content'): Content
{
$content = new Content();
$content->setId($path);
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Controller/RedirectControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class RedirectControllerTest extends BaseTestCase

private RedirectController $controller;

public function setUp(): void
protected function setUp(): void
{
parent::setUp();
$this->db('PHPCR')->createTestNode();
Expand Down
9 changes: 6 additions & 3 deletions tests/Functional/Doctrine/Orm/OrmTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\Doctrine\Orm;

use Doctrine\ODM\PHPCR\DocumentManager;
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
use Doctrine\Persistence\ObjectManager;
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\Route;
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase as ComponentBaseTestCase;

Expand All @@ -23,7 +26,7 @@ protected static function getKernelConfiguration(): array
];
}

protected function clearDb($model)
protected function clearDb($model): void
{
if (\is_array($model)) {
foreach ($model as $singleModel) {
Expand All @@ -40,12 +43,12 @@ protected function clearDb($model)
$this->getDm()->flush();
}

protected function getDm()
protected function getDm(): DocumentManager|ObjectManager|DocumentManagerInterface
{
return $this->db('ORM')->getOm();
}

protected function createRoute($name, $path)
protected function createRoute($name, $path): Route
{
// split path in static and variable part
preg_match('{^(.*?)(/[^/]*\{.*)?$}', $path, $paths);
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Doctrine/Orm/RedirectRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class RedirectRouteTest extends OrmTestCase
{
private RedirectController $controller;

public function setUp(): void
protected function setUp(): void
{
parent::setUp();
$this->clearDb(Route::class);
$this->clearDb(RedirectRoute::class);

$this->controller = new RedirectController($this->getContainer()->get('router'));
$this->controller = new RedirectController(self::getContainer()->get('router'));
}

public function testRedirectDoctrine(): void
Expand Down
9 changes: 5 additions & 4 deletions tests/Functional/Doctrine/Orm/RouteProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@
namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\Doctrine\Orm;

use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\Route;
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\RouteProvider;
use Symfony\Component\HttpFoundation\Request;

class RouteProviderTest extends OrmTestCase
{
private $repository;
private RouteProvider $repository;

public function setUp(): void
protected function setUp(): void
{
parent::setUp();
$this->clearDb(Route::class);

$this->repository = $this->getContainer()->get('cmf_routing.route_provider');
$this->repository = self::getContainer()->get('cmf_routing.route_provider');
}

public function testGetRouteCollectionForRequest()
public function testGetRouteCollectionForRequest(): void
{
$this->createRoute('route1', '/test');
$this->createRoute('route2', '/test/child');
Expand Down
8 changes: 4 additions & 4 deletions tests/Functional/Doctrine/Phpcr/RedirectRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@

class RedirectRouteTest extends BaseTestCase
{
public const ROUTE_ROOT = '/test/redirectroute';
private const ROUTE_ROOT = '/test/redirectroute';

public function setUp(): void
protected function setUp(): void
{
parent::setUp();
$this->db('PHPCR')->createTestNode();
$this->createRoute(self::ROUTE_ROOT);
}

public function testRedirectDoctrine()
public function testRedirectDoctrine(): void
{
$content = $this->createContent();
$root = $this->getDm()->find(null, self::ROUTE_ROOT);
Expand Down Expand Up @@ -57,7 +57,7 @@ public function testRedirectDoctrine()
$this->assertEquals(['test' => 'toast'], $defaults);
}

public function testSetContent()
public function testSetContent(): void
{
$content = $this->createMock(RouteReferrersReadInterface::class);
$redirect = new RedirectRoute();
Expand Down
21 changes: 10 additions & 11 deletions tests/Functional/Doctrine/Phpcr/RouteProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@

class RouteProviderTest extends BaseTestCase
{
public const ROUTE_ROOT = '/test/routing';
private const ROUTE_ROOT = '/test/routing';

/** @var RouteProvider */
private $repository;
private RouteProvider $repository;

public function setUp(): void
protected function setUp(): void
{
parent::setUp();
$this->db('PHPCR')->createTestNode();
$this->createRoute(self::ROUTE_ROOT);
$this->repository = $this->getContainer()->get('cmf_routing.route_provider');
$this->repository = self::getContainer()->get('cmf_routing.route_provider');
}

private function buildRoutes()
private function buildRoutes(): void
{
$root = $this->getDm()->find(null, self::ROUTE_ROOT);

Expand All @@ -58,7 +57,7 @@ private function buildRoutes()
$this->getDm()->clear();
}

public function testGetRouteCollectionForRequest()
public function testGetRouteCollectionForRequest(): void
{
$this->buildRoutes();

Expand All @@ -83,7 +82,7 @@ public function testGetRouteCollectionForRequest()
$this->assertNull($iterator->current()->getDefault('_format'));
}

public function testGetRouteCollectionForRequestFormat()
public function testGetRouteCollectionForRequestFormat(): void
{
$this->buildRoutes();

Expand Down Expand Up @@ -111,7 +110,7 @@ public function testGetRouteCollectionForRequestFormat()
/**
* The root route will always be found.
*/
public function testGetRouteCollectionForRequestNonPhpcrUrl()
public function testGetRouteCollectionForRequestNonPhpcrUrl(): void
{
$routes = $this->repository->getRouteCollectionForRequest(Request::create('http://localhost/'));
$this->assertInstanceOf(RouteCollection::class, $routes);
Expand All @@ -126,14 +125,14 @@ public function testGetRouteCollectionForRequestNonPhpcrUrl()
/**
* The root route will always be found.
*/
public function testGetRouteCollectionForRequestColonInUrl()
public function testGetRouteCollectionForRequestColonInUrl(): void
{
$collection = $this->repository->getRouteCollectionForRequest(Request::create('http://foo.com/jcr:content'));
$this->assertInstanceOf(RouteCollection::class, $collection);
$this->assertCount(0, $collection);
}

public function testGetRoutesByNames()
public function testGetRoutesByNames(): void
{
$this->buildRoutes();

Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Doctrine/Phpcr/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

class RouteTest extends BaseTestCase
{
public const ROUTE_ROOT = '/test/routing';
private const ROUTE_ROOT = '/test/routing';

public function setUp(): void
protected function setUp(): void
{
parent::setUp();
$this->db('PHPCR')->createTestNode();
Expand Down
Loading

0 comments on commit 1d971a6

Please sign in to comment.