Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
cs fixes
Browse files Browse the repository at this point in the history
removed providers from faker
  • Loading branch information
danielbannert committed Jul 31, 2018
1 parent 8cbec9d commit 6fafa5e
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use Narrowspark\CS\Config\Config;
$config = new Config();
$config->getFinder()
->files()
->in(__DIR__ . DIRECTORY_SEPARATOR . 'src')
->in(__DIR__)
->exclude('build')
->exclude('vendor')
->name('*.php')
Expand Down
11 changes: 1 addition & 10 deletions src/TestingHelper/Traits/FakerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,14 @@ trait FakerTrait
* You get always the same generated data.
*
* @param string $locale
* @param array $providers
*
* @return \Faker\Generator
*/
public static function getFaker(string $locale = 'en_US', array $providers = []): Generator
public static function getFaker(string $locale = 'en_US'): Generator
{
if (! \array_key_exists($locale, self::$fakers)) {
$faker = Factory::create();

$providers = \array_filter($providers);

if (! empty($providers)) {
foreach ($providers as $provider) {
$faker->addProvider($provider);
}
}

$faker->seed(9000);

self::$fakers[$locale] = $faker;
Expand Down
15 changes: 9 additions & 6 deletions tests/ArrayContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@
use Narrowspark\TestingHelper\ArrayContainer;
use PHPUnit\Framework\TestCase;

class ArrayContainerTest extends TestCase
/**
* @internal
*/
final class ArrayContainerTest extends TestCase
{
public function testSetGetAndHas(): void
{
$container = new ArrayContainer(['bar' => 'foo']);

self::assertSame('foo', $container->get('bar'));
self::assertTrue($container->has('bar'));
static::assertSame('foo', $container->get('bar'));
static::assertTrue($container->has('bar'));

$container->set('baz', 'bar');

self::assertSame('bar', $container->get('baz'));
self::assertTrue($container->has('baz'));
static::assertSame('bar', $container->get('baz'));
static::assertTrue($container->has('baz'));
}

public function testCheckIfContainerHasAInterface(): void
{
$container = new ArrayContainer(['bar' => 'foo']);

self::assertInstanceOf('\Psr\Container\ContainerInterface', $container);
static::assertInstanceOf('\Psr\Container\ContainerInterface', $container);
}
}
4 changes: 2 additions & 2 deletions tests/Fixture/MockObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function setCreated(DateTime $created)
/**
* @return \DateTime
*/
public function getCreated()
public function getCreated(): DateTime
{
return $this->created;
}
Expand Down Expand Up @@ -95,7 +95,7 @@ public function getNonChainable()
*/
public function setManipulated($manipulated)
{
$this->manipulated = mb_strtoupper($manipulated);
$this->manipulated = \mb_strtoupper($manipulated);

return $this;
}
Expand Down
19 changes: 10 additions & 9 deletions tests/Middleware/CallableMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseFactoryInterface;

class CallableMiddlewareTest extends TestCase
/**
* @internal
*/
final class CallableMiddlewareTest extends TestCase
{
/**
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage The value returned must be "scalar" or an object with "__toString" method.
*/
public function testMiddlewareThrowErrorOnScalarType(): void
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('The value returned must be "scalar" or an object with "__toString" method.');

$middleware = new CallableMiddleware(
function () {
return new class() {
Expand All @@ -31,12 +33,11 @@ function () {
);
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage No ResponseFactory class found.
*/
public function testConstructorThrowErrorOnWrongResponseFactory2(): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('No ResponseFactory class found.');

$middleware = new CallableMiddleware(
function () {
return '';
Expand Down
7 changes: 5 additions & 2 deletions tests/Middleware/DelegateMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
use Narrowspark\TestingHelper\Phpunit\MockeryTestCase;
use Psr\Http\Message\ResponseInterface;

class DelegateMiddlewareTest extends MockeryTestCase
/**
* @internal
*/
final class DelegateMiddlewareTest extends MockeryTestCase
{
public function testCallCallableWithProcess(): void
{
$middleware = new RequestHandlerMiddleware(function () {
return $this->mock(ResponseInterface::class);
});

self::assertInstanceOf(
static::assertInstanceOf(
ResponseInterface::class,
$middleware->handle(new ServerRequest('GET', '/'))
);
Expand Down
40 changes: 21 additions & 19 deletions tests/Middleware/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\RequestHandlerInterface;

class DispatcherTest extends TestCase
/**
* @internal
*/
final class DispatcherTest extends TestCase
{
/**
* @var \GuzzleHttp\Psr7\ServerRequest
Expand All @@ -30,15 +33,15 @@ protected function setUp(): void
{
parent::setUp();

$this->serverRequest = new ServerRequest('GET', '/');
$this->responseFactory = new class () implements ResponseFactoryInterface {
$this->serverRequest = new ServerRequest('GET', '/');
$this->responseFactory = new class() implements ResponseFactoryInterface {
/**
* Create a new response.
*
* @param int $code HTTP status code; defaults to 200
* @param string $reasonPhrase Reason phrase to associate with status code
* in generated response; if none is provided implementations MAY use
* the defaults as suggested in the HTTP specification.
* @param int $code HTTP status code; defaults to 200
* @param string $reasonPhrase reason phrase to associate with status code
* in generated response; if none is provided implementations MAY use
* the defaults as suggested in the HTTP specification
*
* @return ResponseInterface
*/
Expand All @@ -49,12 +52,11 @@ public function createResponse(int $code = 200, string $reasonPhrase = ''): Resp
};
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage Unresolved request: middleware stack exhausted with no result.
*/
public function testDispatcherWithEmptyStack(): void
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Unresolved request: middleware stack exhausted with no result.');

$dispatcher = new Dispatcher([]);
$dispatcher->dispatch($this->serverRequest);
}
Expand Down Expand Up @@ -84,8 +86,8 @@ function (): void {

$response = $dispatcher->dispatch($this->serverRequest);

self::assertInstanceOf(ResponseInterface::class, $response);
self::assertEquals('123', (string) $response->getBody());
static::assertInstanceOf(ResponseInterface::class, $response);
static::assertEquals('123', (string) $response->getBody());
}

public function testNestedDispatcher(): void
Expand Down Expand Up @@ -157,17 +159,17 @@ function ($request, RequestHandlerInterface $handler) {

$response = $dispatcher3->dispatch($this->serverRequest);

self::assertInstanceOf(ResponseInterface::class, $response);
self::assertEquals('1234567', (string) $response->getBody());
static::assertInstanceOf(ResponseInterface::class, $response);
static::assertEquals('1234567', (string) $response->getBody());

$response = $dispatcher2->dispatch($this->serverRequest);

self::assertInstanceOf(ResponseInterface::class, $response);
self::assertEquals('12345', (string) $response->getBody());
static::assertInstanceOf(ResponseInterface::class, $response);
static::assertEquals('12345', (string) $response->getBody());

$response = $dispatcher1->dispatch($this->serverRequest);

self::assertInstanceOf(ResponseInterface::class, $response);
self::assertEquals('123', (string) $response->getBody());
static::assertInstanceOf(ResponseInterface::class, $response);
static::assertEquals('123', (string) $response->getBody());
}
}
11 changes: 7 additions & 4 deletions tests/Phpunit/MockeryTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@
use Narrowspark\TestingHelper\Phpunit\MockeryTestCase;
use Narrowspark\TestingHelper\Tests\Fixture\FooObject;

class MockeryTestCaseTest extends MockeryTestCase
/**
* @internal
*/
final class MockeryTestCaseTest extends MockeryTestCase
{
public function testAllowMockingNonExistentMethods(): void
{
self::assertFalse(Mock::getConfiguration()->mockingNonExistentMethodsAllowed());
static::assertFalse(Mock::getConfiguration()->mockingNonExistentMethodsAllowed());

$this->allowMockingNonExistentMethods(true);

self::assertTrue(Mock::getConfiguration()->mockingNonExistentMethodsAllowed());
static::assertTrue(Mock::getConfiguration()->mockingNonExistentMethodsAllowed());
}

public function testMock(): void
{
$mocked = $this->mock(FooObject::class);

self::assertInstanceOf(get_class($mocked), $mocked);
static::assertInstanceOf(\get_class($mocked), $mocked);
}
}
32 changes: 16 additions & 16 deletions tests/Traits/AssertGetterSetterTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
use Narrowspark\TestingHelper\Traits\AssertGetterSetterTrait;
use PHPUnit\Framework\TestCase;

class AssertGetterSetterTraitTest extends TestCase
/**
* @internal
*/
final class AssertGetterSetterTraitTest extends TestCase
{
use AssertGetterSetterTrait;

protected $object;

public function setUp(): void
protected function setUp(): void
{
$this->object = new MockObject();
}
Expand Down Expand Up @@ -94,11 +97,11 @@ public function testGetterSetterArray(): void

/**
* Failure because we can not check the default on properties set during instantiation.
*
* @expectedException \PHPUnit\Framework\ExpectationFailedException
*/
public function testGetterAndSetterDefaultDate(): void
{
$this->expectException(\PHPUnit\Framework\ExpectationFailedException::class);

$dateTime = new DateTime();

self::assertGetterSetter(
Expand All @@ -111,24 +114,22 @@ public function testGetterAndSetterDefaultDate(): void
);
}

/**
* @expectedException \PHPUnit\Framework\ExpectationFailedException
* @expectedExceptionMessage Object does not contain the specified getter method "getNonExistent".
*/
public function testNonExistentGetter(): void
{
$this->expectException(\PHPUnit\Framework\ExpectationFailedException::class);
$this->expectExceptionMessage('Object does not contain the specified getter method "getNonExistent".');

self::assertGetterSetter(
$this->object,
'getNonExistent'
);
}

/**
* @expectedException \PHPUnit\Framework\ExpectationFailedException
* @expectedExceptionMessage Object does not contain the specified setter method "setId".
*/
public function testGetterAndNonExistentSetter(): void
{
$this->expectException(\PHPUnit\Framework\ExpectationFailedException::class);
$this->expectExceptionMessage('Object does not contain the specified setter method "setId".');

self::assertGetterSetter(
$this->object,
'getId',
Expand All @@ -137,12 +138,11 @@ public function testGetterAndNonExistentSetter(): void
);
}

/**
* @expectedException \PHPUnit\Framework\ExpectationFailedException
* @expectedExceptionMessage Object setter (setNonChainable) is not chainable.
*/
public function testGetterAndSetterNonChainableAsChainable(): void
{
$this->expectException(\PHPUnit\Framework\ExpectationFailedException::class);
$this->expectExceptionMessage('Object setter (setNonChainable) is not chainable.');

self::assertGetterSetter(
$this->object,
'getNonChainable',
Expand Down
5 changes: 4 additions & 1 deletion tests/Traits/DateAssertionTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
use Narrowspark\TestingHelper\Traits\DateAssertionTrait;
use PHPUnit\Framework\TestCase;

class DateAssertionTraitTest extends TestCase
/**
* @internal
*/
final class DateAssertionTraitTest extends TestCase
{
use DateAssertionTrait;

Expand Down
Loading

0 comments on commit 6fafa5e

Please sign in to comment.