Skip to content

Commit

Permalink
[shopsys] introduced new coding standards (#2617)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasLudvik committed Jun 9, 2023
2 parents 3d04732 + 30cc2f6 commit b6f9130
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 89 deletions.
7 changes: 2 additions & 5 deletions src/Annotation/DataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
*/
class DataSet
{
/**
* @var int
*/
public $statusCode = 200;
public int $statusCode = 200;

/**
* @var \Shopsys\HttpSmokeTesting\Annotation\Parameter[]
*/
public $parameters = [];
public array $parameters = [];
}
6 changes: 2 additions & 4 deletions src/Annotation/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
class Parameter
{
/**
* @var string
* @Required()
*/
public $name;
public string $name;

/**
* @var string
* @Required()
*/
public $value;
public string $value;
}
2 changes: 2 additions & 0 deletions src/Auth/AuthInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting\Auth;

use Symfony\Component\HttpFoundation\Request;
Expand Down
12 changes: 4 additions & 8 deletions src/Auth/BasicHttpAuth.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting\Auth;

use Symfony\Component\HttpFoundation\Request;

class BasicHttpAuth implements AuthInterface
{
/**
* @var string
*/
private $username;
private string $username;

/**
* @var string|null
*/
private $password;
private ?string $password = null;

/**
* @param string $username
Expand Down
2 changes: 2 additions & 0 deletions src/Auth/NoAuth.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting\Auth;

use Symfony\Component\HttpFoundation\Request;
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/RouteNameNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting\Exception;

use Exception;
Expand All @@ -14,7 +16,7 @@ public function __construct($routeName)
$routeNames = (array)$routeName;

parent::__construct(
'Route name' . (count($routeNames) !== 1 ? 's' : '') . ' "' . implode('", "', $routeNames) . '" not found!'
'Route name' . (count($routeNames) !== 1 ? 's' : '') . ' "' . implode('", "', $routeNames) . '" not found!',
);
}
}
8 changes: 5 additions & 3 deletions src/HttpSmokeTestCase.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting;

use Shopsys\HttpSmokeTesting\RouterAdapter\SymfonyRouterAdapter;
Expand Down Expand Up @@ -85,7 +87,7 @@ final public function httpResponseTestDataProvider()
function (RequestDataSet $requestDataSet) {
return [$requestDataSet];
},
$requestDataSets
$requestDataSets,
);
}

Expand Down Expand Up @@ -141,12 +143,12 @@ protected function assertResponse(Response $response, RequestDataSet $requestDat
'Failed asserting that status code %d for route "%s" is identical to expected %d',
$response->getStatusCode(),
$requestDataSet->getRouteName(),
$requestDataSet->getExpectedStatusCode()
$requestDataSet->getExpectedStatusCode(),
);
$this->assertSame(
$requestDataSet->getExpectedStatusCode(),
$response->getStatusCode(),
$this->getMessageWithDebugNotes($requestDataSet, $failMessage)
$this->getMessageWithDebugNotes($requestDataSet, $failMessage),
);
}

Expand Down
30 changes: 10 additions & 20 deletions src/RequestDataSet.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting;

use Shopsys\HttpSmokeTesting\Auth\AuthInterface;
Expand All @@ -10,40 +12,28 @@ class RequestDataSet implements RequestDataSetConfig
{
private const DEFAULT_EXPECTED_STATUS_CODE = 200;

/**
* @var string
*/
private $routeName;
private string $routeName;

/**
* @var bool
*/
private $skipped;
private bool $skipped;

/**
* @var \Shopsys\HttpSmokeTesting\Auth\AuthInterface|null
*/
private $auth;
private ?AuthInterface $auth = null;

/**
* @var int|null
*/
private $expectedStatusCode;
private ?int $expectedStatusCode = null;

/**
* @var array
* @var array<string, mixed>
*/
private $parameters;
private array $parameters;

/**
* @var string[]
*/
private $debugNotes;
private array $debugNotes;

/**
* @var callable[]
*/
private $callsDuringTestExecution;
private array $callsDuringTestExecution;

/**
* @param string $routeName
Expand Down
2 changes: 2 additions & 0 deletions src/RequestDataSetConfig.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting;

use Shopsys\HttpSmokeTesting\Auth\AuthInterface;
Expand Down
17 changes: 5 additions & 12 deletions src/RequestDataSetGenerator.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting;

use Shopsys\HttpSmokeTesting\Annotation\DataSet;
use Shopsys\HttpSmokeTesting\Annotation\Skipped;

class RequestDataSetGenerator implements RouteConfig
{
/**
* @var \Shopsys\HttpSmokeTesting\RouteInfo
*/
private $routeInfo;

/**
* @var \Shopsys\HttpSmokeTesting\RequestDataSet
*/
private $defaultRequestDataSet;
private RequestDataSet $defaultRequestDataSet;

/**
* @var \Shopsys\HttpSmokeTesting\RequestDataSet[]
*/
private $extraRequestDataSets;
private array $extraRequestDataSets;

/**
* @param \Shopsys\HttpSmokeTesting\RouteInfo $routeInfo
*/
public function __construct(RouteInfo $routeInfo)
public function __construct(private readonly RouteInfo $routeInfo)
{
$this->routeInfo = $routeInfo;
$this->defaultRequestDataSet = new RequestDataSet($this->routeInfo->getRouteName());
$this->extraRequestDataSets = [];
}
Expand Down
2 changes: 2 additions & 0 deletions src/RequestDataSetGeneratorFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting;

class RequestDataSetGeneratorFactory
Expand Down
2 changes: 2 additions & 0 deletions src/RouteConfig.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting;

interface RouteConfig
Expand Down
10 changes: 3 additions & 7 deletions src/RouteConfigCustomizer.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting;

use Shopsys\HttpSmokeTesting\Exception\RouteNameNotFoundException;

class RouteConfigCustomizer
{
/**
* @var \Shopsys\HttpSmokeTesting\RequestDataSetGenerator[]
*/
private $requestDataSetGenerators;

/**
* @param \Shopsys\HttpSmokeTesting\RequestDataSetGenerator[] $requestDataSetGenerators
*/
public function __construct(array $requestDataSetGenerators)
public function __construct(private readonly array $requestDataSetGenerators)
{
$this->requestDataSetGenerators = $requestDataSetGenerators;
}

/**
Expand Down
21 changes: 4 additions & 17 deletions src/RouteInfo.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting;

use Symfony\Component\Routing\Route;

class RouteInfo
{
/**
* @var string
*/
private $routeName;

/**
* @var \Symfony\Component\Routing\Route
*/
private $route;

/**
* @var array
*/
private $annotations;
private string $routeName;

/**
* @param string $routeName
* @param \Symfony\Component\Routing\Route $route
* @param array $annotations
*/
public function __construct($routeName, Route $route, array $annotations = [])
public function __construct($routeName, private readonly Route $route, private readonly array $annotations = [])
{
$this->routeName = $routeName;
$this->route = $route;
$this->annotations = $annotations;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/RouterAdapter/RouterAdapterInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting\RouterAdapter;

use Shopsys\HttpSmokeTesting\RequestDataSet;
Expand Down
12 changes: 4 additions & 8 deletions src/RouterAdapter/SymfonyRouterAdapter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Shopsys\HttpSmokeTesting\RouterAdapter;

use Doctrine\Common\Annotations\AnnotationReader;
Expand All @@ -15,21 +17,15 @@

class SymfonyRouterAdapter implements RouterAdapterInterface
{
/**
* @var \Symfony\Component\Routing\RouterInterface
*/
private $router;

private $annotationsReader;
private AnnotationReader $annotationsReader;

/**
* @param \Symfony\Component\Routing\RouterInterface $router
*/
public function __construct(RouterInterface $router)
public function __construct(private readonly RouterInterface $router)
{
AnnotationRegistry::registerLoader('class_exists');

$this->router = $router;
$this->annotationsReader = new AnnotationReader();
}

Expand Down
8 changes: 5 additions & 3 deletions tests/Unit/RequestDataSetGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests\HttpSmokeTesting\Unit;

use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -66,12 +68,12 @@ private function createRequestDataSetGenerator($routePath, $routeName, array $an
public function testGeneratorGenerateRequestDataSetFromDataSetAnnotation(
DataSet $dataSet,
int $statusCode,
array $parameters
array $parameters,
) {
$requestDataSetGenerator = $this->createRequestDataSetGenerator(
'test_route_path',
'test_route_name',
[$dataSet]
[$dataSet],
);
$requestDataSets = $requestDataSetGenerator->generateRequestDataSets();

Expand Down Expand Up @@ -105,7 +107,7 @@ public function testGeneratorGeneratesRequestDataSetsFromDataSetAnnotations()
$requestDataSetGenerator = $this->createRequestDataSetGenerator(
'test_route_path',
'test_route_name',
$annotations
$annotations,
);

$requestDataSets = $requestDataSetGenerator->generateRequestDataSets();
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/RouterAdapter/SymfonyRouterAdapterTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests\HttpSmokeTesting\Unit\RouterAdapter;

use Doctrine\Common\Annotations\AnnotationReader;
Expand All @@ -19,7 +21,7 @@ public function testGetAllRouteInfoExtractsInformationFromRouteCollection()
{
$router = new Router(
new AnnotatedRouteControllerLoader(new AnnotationReader()),
TestController::class
TestController::class,
);

$adapter = new SymfonyRouterAdapter($router);
Expand Down

0 comments on commit b6f9130

Please sign in to comment.