Skip to content

Commit

Permalink
Split Laravel tests from GetValueFactoryTest to Laravel tests folder
Browse files Browse the repository at this point in the history
  • Loading branch information
pionl committed Jul 25, 2023
1 parent b262118 commit 0597fd5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 61 deletions.
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

$config->skip([
NewlineAfterStatementRector::class,
StaticArrowFunctionRector::class => './tests/GetValueFactoryTest.php',
StaticArrowFunctionRector::class => './tests/Laravel/GetValueFactoryLaravelTest.php',
SimplifyBoolIdenticalTrueRector::class,
]);
};
60 changes: 0 additions & 60 deletions tests/GetValueFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

namespace Wrkflow\GetValueTests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use PHPUnit\Framework\TestCase;
use SimpleXMLElement;
use Wrkflow\GetValue\GetValue;
use Wrkflow\GetValue\GetValueFactory;
use Wrkflow\GetValue\Strategies\NoTransformerStrategy;
use Wrkflow\GetValueTests\Builders\CustomExceptionBuilder;
use Wrkflow\GetValueTests\Mocks\ValidatorMock;

class GetValueFactoryTest extends TestCase
{
Expand Down Expand Up @@ -57,63 +54,6 @@ public function testArray(): void
$getValue->getRequiredString('no_value');
}

public function testRequestAll(): void
{
if (class_exists(Request::class) === false) {
$this->markTestSkipped('Laravel not installed.');
}

$getValue = $this->factory->requestAll(new Request([
'test' => 'This is a test',
'not_validated' => 'Test',
]));

$this->assertEquals('This is a test', $getValue->getRequiredString('test'));
$this->assertEquals('Test', $getValue->getString('not_validated'));
}

public function testRequestValidated(): void
{
if (class_exists(Request::class) === false) {
$this->markTestSkipped('Laravel not installed.');
}

$getValue = $this->factory->request($this->getFormRequest());

$this->assertEquals('This is a test', $getValue->getRequiredString('test'));
$this->assertNull($getValue->getString('not_validated'));
}

public function testRequestAllWithFormRequest(): void
{
if (class_exists(Request::class) === false) {
$this->markTestSkipped('Laravel not installed.');
}

$request = $this->getFormRequest();
$getValue = $this->factory->requestAll($request);

$this->assertEquals('This is a test', $getValue->getRequiredString('test'));
$this->assertEquals('Test', $getValue->getString('not_validated'));
}

protected function getFormRequest(): FormRequest
{
$request = new FormRequest([
'test' => 'This is a test',
'not_validated' => 'Test',
]);
$validator = new ValidatorMock([
'test' => 'This is a test',
]);
FormRequest::macro('validate', fn () => $validator->validate());
$request->setValidator($validator);
$request->validate([
'test' => 'string',
]);
return $request;
}

protected function createArray(): GetValue
{
return $this->factory->array([
Expand Down
68 changes: 68 additions & 0 deletions tests/Laravel/GetValueFactoryLaravelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

namespace Wrkflow\GetValueTests\Laravel;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use PHPUnit\Framework\TestCase;
use Wrkflow\GetValue\GetValueFactory;
use Wrkflow\GetValueTests\Mocks\ValidatorMock;

class GetValueFactoryLaravelTest extends TestCase
{
private GetValueFactory $factory;

protected function setUp(): void
{
parent::setUp();

$this->factory = new GetValueFactory();
}

public function testRequestAll(): void
{
$getValue = $this->factory->requestAll(new Request([
'test' => 'This is a test',
'not_validated' => 'Test',
]));

$this->assertEquals('This is a test', $getValue->getRequiredString('test'));
$this->assertEquals('Test', $getValue->getString('not_validated'));
}

public function testRequestValidated(): void
{
$getValue = $this->factory->request($this->getFormRequest());

$this->assertEquals('This is a test', $getValue->getRequiredString('test'));
$this->assertNull($getValue->getString('not_validated'));
}

public function testRequestAllWithFormRequest(): void
{
$request = $this->getFormRequest();
$getValue = $this->factory->requestAll($request);

$this->assertEquals('This is a test', $getValue->getRequiredString('test'));
$this->assertEquals('Test', $getValue->getString('not_validated'));
}

protected function getFormRequest(): FormRequest
{
$request = new FormRequest([
'test' => 'This is a test',
'not_validated' => 'Test',
]);
$validator = new ValidatorMock([
'test' => 'This is a test',
]);
FormRequest::macro('validate', fn () => $validator->validate());
$request->setValidator($validator);
$request->validate([
'test' => 'string',
]);
return $request;
}
}

0 comments on commit 0597fd5

Please sign in to comment.