php cs fixer
This commit is contained in:
parent
26abaeb739
commit
189493b045
17 changed files with 44 additions and 43 deletions
|
|
@ -14,7 +14,7 @@ class JsonNodeRepository implements NodeRepository
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private TextRepository $textRepository,
|
private TextRepository $textRepository,
|
||||||
) {
|
) {
|
||||||
$this->filePath = __DIR__.'/../../data/nodes.json';
|
$this->filePath = __DIR__ . '/../../data/nodes.json';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(CreateNodeDto $dto): Node
|
public function create(CreateNodeDto $dto): Node
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class JsonTextRepository implements TextRepository
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->filePath = __DIR__.'/../../data/texts.json';
|
$this->filePath = __DIR__ . '/../../data/texts.json';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(CreateTextDto $dto): Text
|
public function create(CreateTextDto $dto): Text
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ class ViewController
|
||||||
{
|
{
|
||||||
public function admin(Response $response): Response
|
public function admin(Response $response): Response
|
||||||
{
|
{
|
||||||
$html = file_get_contents(__DIR__.'/../../views/templates/admin.php', true);
|
$html = file_get_contents(__DIR__ . '/../../views/templates/admin.php', true);
|
||||||
$response->getBody()->write($html);
|
$response->getBody()->write($html);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
|
@ -16,7 +16,7 @@ class ViewController
|
||||||
|
|
||||||
public function texts(Response $response): Response
|
public function texts(Response $response): Response
|
||||||
{
|
{
|
||||||
$html = file_get_contents(__DIR__.'/../../views/templates/texts.php', true);
|
$html = file_get_contents(__DIR__ . '/../../views/templates/texts.php', true);
|
||||||
$response->getBody()->write($html);
|
$response->getBody()->write($html);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
|
@ -24,7 +24,7 @@ class ViewController
|
||||||
|
|
||||||
public function text(Response $response): Response
|
public function text(Response $response): Response
|
||||||
{
|
{
|
||||||
$html = file_get_contents(__DIR__.'/../../views/templates/text.php', true);
|
$html = file_get_contents(__DIR__ . '/../../views/templates/text.php', true);
|
||||||
$response->getBody()->write($html);
|
$response->getBody()->write($html);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use App\View\ViewController;
|
||||||
use App\Text\TextController;
|
use App\Text\TextController;
|
||||||
use App\Node\NodeController;
|
use App\Node\NodeController;
|
||||||
|
|
||||||
$container = require __DIR__.'/container.php';
|
$container = require __DIR__ . '/container.php';
|
||||||
$app = Bridge::create($container);
|
$app = Bridge::create($container);
|
||||||
|
|
||||||
// change first param to false for production
|
// change first param to false for production
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
$texts = [
|
$texts = [
|
||||||
[
|
[
|
||||||
'id' => 0,
|
'id' => 0,
|
||||||
'name' => 'test text'
|
'name' => 'test text',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -28,6 +28,6 @@ $fileDataMap = [
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($fileDataMap as $file => $data) {
|
foreach ($fileDataMap as $file => $data) {
|
||||||
$path = __DIR__."/$file";
|
$path = __DIR__ . "/$file";
|
||||||
file_put_contents($path, json_encode($data, JSON_PRETTY_PRINT));
|
file_put_contents($path, json_encode($data, JSON_PRETTY_PRINT));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ $files = [
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
echo __DIR__."/$file";
|
echo __DIR__ . "/$file";
|
||||||
$path = __DIR__."/$file";
|
$path = __DIR__ . "/$file";
|
||||||
file_put_contents($path, json_encode([], JSON_PRETTY_PRINT));
|
file_put_contents($path, json_encode([], JSON_PRETTY_PRINT));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
require __DIR__ . '/../vendor/autoload.php';
|
require __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
$app = require __DIR__.'/../bootstrap/app.php';
|
$app = require __DIR__ . '/../bootstrap/app.php';
|
||||||
|
|
||||||
$app->run();
|
$app->run();
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class FakeTextRepository implements TextRepository
|
||||||
{
|
{
|
||||||
$text = array_find(
|
$text = array_find(
|
||||||
$this->existingTexts,
|
$this->existingTexts,
|
||||||
function (Text $text) use ($id){
|
function (Text $text) use ($id) {
|
||||||
return $text->getId() === $id;
|
return $text->getId() === $id;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ class BulkCreateNodesTest extends TestCase
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->textRepo = new FakeTextRepository;
|
$this->textRepo = new FakeTextRepository();
|
||||||
$this->textRepo->create(new CreateTextDto(name: 'text'));
|
$this->textRepo->create(new CreateTextDto(name: 'text'));
|
||||||
|
|
||||||
$this->nodeRepo = new FakeNodeRepository;
|
$this->nodeRepo = new FakeNodeRepository();
|
||||||
$text = $this->textRepo->find(0);
|
$text = $this->textRepo->find(0);
|
||||||
$this->parentNode = $this->nodeRepo->create(new CreateNodeDto(
|
$this->parentNode = $this->nodeRepo->create(new CreateNodeDto(
|
||||||
text: $text,
|
text: $text,
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,11 @@ class CreateNodeTest extends TestCase
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->textRepo = new FakeTextRepository;
|
$this->textRepo = new FakeTextRepository();
|
||||||
$this->textRepo->create(new CreateTextDto(
|
$this->textRepo->create(new CreateTextDto(
|
||||||
name: 'text'
|
name: 'text'
|
||||||
));
|
));
|
||||||
$this->nodeRepo = new FakeNodeRepository;
|
$this->nodeRepo = new FakeNodeRepository();
|
||||||
$this->useCase = new CreateNode(
|
$this->useCase = new CreateNode(
|
||||||
nodeRepo: $this->nodeRepo,
|
nodeRepo: $this->nodeRepo,
|
||||||
textRepo: $this->textRepo,
|
textRepo: $this->textRepo,
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,11 @@ class CreatePlanTest extends TestCase
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->planRepo = new FakePlanRepository;
|
$this->planRepo = new FakePlanRepository();
|
||||||
$this->userRepo = new FakeUserRepository;
|
$this->userRepo = new FakeUserRepository();
|
||||||
$this->textRepo = new FakeTextRepository;
|
$this->textRepo = new FakeTextRepository();
|
||||||
$this->nodeRepo = new FakeNodeRepository;
|
$this->nodeRepo = new FakeNodeRepository();
|
||||||
$this->scheduledNodeRepo = new FakeScheduledNodeRepository;
|
$this->scheduledNodeRepo = new FakeScheduledNodeRepository();
|
||||||
$this->userRepo->create(new CreateUserDto(
|
$this->userRepo->create(new CreateUserDto(
|
||||||
email: new EmailAddress('test@test.com'),
|
email: new EmailAddress('test@test.com'),
|
||||||
));
|
));
|
||||||
|
|
@ -121,7 +121,8 @@ class CreatePlanTest extends TestCase
|
||||||
textId: 0,
|
textId: 0,
|
||||||
));
|
));
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
1, $this->scheduledNodeRepo->getNumberOfTimesCreateCalled()
|
1,
|
||||||
|
$this->scheduledNodeRepo->getNumberOfTimesCreateCalled()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ class CreateScheduledNodeTest extends TestCase
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->scheduledNodeRepo = new FakeScheduledNodeRepository;
|
$this->scheduledNodeRepo = new FakeScheduledNodeRepository();
|
||||||
$this->planRepo = new FakePlanRepository;
|
$this->planRepo = new FakePlanRepository();
|
||||||
$this->planRepo->create(new CreatePlanDto(
|
$this->planRepo->create(new CreatePlanDto(
|
||||||
name: 'testplan',
|
name: 'testplan',
|
||||||
user: new User(0, new EmailAddress('test@test.com')),
|
user: new User(0, new EmailAddress('test@test.com')),
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ class CreateTextTest extends TestCase
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->textRepo = new FakeTextRepository;
|
$this->textRepo = new FakeTextRepository();
|
||||||
$this->nodeRepo = new FakeNodeRepository;
|
$this->nodeRepo = new FakeNodeRepository();
|
||||||
$this->useCase = new CreateText(
|
$this->useCase = new CreateText(
|
||||||
$this->textRepo,
|
$this->textRepo,
|
||||||
$this->nodeRepo,
|
$this->nodeRepo,
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class CreateUserTest extends TestCase
|
||||||
{
|
{
|
||||||
public function test_create_user(): void
|
public function test_create_user(): void
|
||||||
{
|
{
|
||||||
$userRepo = new FakeUserRepository;
|
$userRepo = new FakeUserRepository();
|
||||||
$useCase = new CreateUser($userRepo);
|
$useCase = new CreateUser($userRepo);
|
||||||
$useCase->execute(new CreateUserRequest(
|
$useCase->execute(new CreateUserRequest(
|
||||||
email: 'test@test.com',
|
email: 'test@test.com',
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,10 @@ class BulkCreateNodesControllerTest extends TestCase
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->textRepo = new FakeTextRepository;
|
$this->textRepo = new FakeTextRepository();
|
||||||
$text = $this->textRepo->create(new CreateTextDto(name: 'test text'));
|
$text = $this->textRepo->create(new CreateTextDto(name: 'test text'));
|
||||||
|
|
||||||
$this->nodeRepo = new FakeNodeRepository;
|
$this->nodeRepo = new FakeNodeRepository();
|
||||||
$this->nodeRepo->create(new CreateNodeDto(
|
$this->nodeRepo->create(new CreateNodeDto(
|
||||||
text: $text,
|
text: $text,
|
||||||
title: 'Root Node',
|
title: 'Root Node',
|
||||||
|
|
@ -44,8 +44,8 @@ class BulkCreateNodesControllerTest extends TestCase
|
||||||
|
|
||||||
private function makeRequest(array $data): ServerRequestInterface
|
private function makeRequest(array $data): ServerRequestInterface
|
||||||
{
|
{
|
||||||
$body = (new StreamFactory())->createStream(json_encode($data));
|
$body = new StreamFactory()->createStream(json_encode($data));
|
||||||
return (new ServerRequestFactory())
|
return new ServerRequestFactory()
|
||||||
->createServerRequest('POST', 'http://localhost/api/nodes/bulk')
|
->createServerRequest('POST', 'http://localhost/api/nodes/bulk')
|
||||||
->withHeader('Content-Type', 'application/json')
|
->withHeader('Content-Type', 'application/json')
|
||||||
->withBody($body);
|
->withBody($body);
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ class NodeControllerTest extends TestCase
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->textRepo = new FakeTextRepository;
|
$this->textRepo = new FakeTextRepository();
|
||||||
$this->textRepo->create(new CreateTextDto(name: 'test text'));
|
$this->textRepo->create(new CreateTextDto(name: 'test text'));
|
||||||
|
|
||||||
$this->nodeRepo = new FakeNodeRepository;
|
$this->nodeRepo = new FakeNodeRepository();
|
||||||
|
|
||||||
$this->controller = new NodeController($this->nodeRepo, $this->textRepo);
|
$this->controller = new NodeController($this->nodeRepo, $this->textRepo);
|
||||||
}
|
}
|
||||||
|
|
@ -93,12 +93,12 @@ class NodeControllerTest extends TestCase
|
||||||
parentNode: null,
|
parentNode: null,
|
||||||
));
|
));
|
||||||
|
|
||||||
$body = (new StreamFactory())->createStream(json_encode([
|
$body = new StreamFactory()->createStream(json_encode([
|
||||||
'textId' => 0,
|
'textId' => 0,
|
||||||
'title' => 'Child Node',
|
'title' => 'Child Node',
|
||||||
'parentNodeId' => $rootNode->getId(),
|
'parentNodeId' => $rootNode->getId(),
|
||||||
]));
|
]));
|
||||||
$request = (new ServerRequestFactory())
|
$request = new ServerRequestFactory()
|
||||||
->createServerRequest('POST', 'http://localhost/api/nodes')
|
->createServerRequest('POST', 'http://localhost/api/nodes')
|
||||||
->withHeader('Content-Type', 'application/json')
|
->withHeader('Content-Type', 'application/json')
|
||||||
->withBody($body);
|
->withBody($body);
|
||||||
|
|
@ -118,11 +118,11 @@ class NodeControllerTest extends TestCase
|
||||||
|
|
||||||
public function test_create_node_returns_400_when_title_missing(): void
|
public function test_create_node_returns_400_when_title_missing(): void
|
||||||
{
|
{
|
||||||
$body = (new StreamFactory())->createStream(json_encode([
|
$body = new StreamFactory()->createStream(json_encode([
|
||||||
'textId' => 0,
|
'textId' => 0,
|
||||||
'parentNodeId' => null,
|
'parentNodeId' => null,
|
||||||
]));
|
]));
|
||||||
$request = (new ServerRequestFactory())
|
$request = new ServerRequestFactory()
|
||||||
->createServerRequest('POST', 'http://localhost/api/nodes')
|
->createServerRequest('POST', 'http://localhost/api/nodes')
|
||||||
->withHeader('Content-Type', 'application/json')
|
->withHeader('Content-Type', 'application/json')
|
||||||
->withBody($body);
|
->withBody($body);
|
||||||
|
|
@ -138,12 +138,12 @@ class NodeControllerTest extends TestCase
|
||||||
|
|
||||||
public function test_create_node_returns_404_when_text_not_found(): void
|
public function test_create_node_returns_404_when_text_not_found(): void
|
||||||
{
|
{
|
||||||
$body = (new StreamFactory())->createStream(json_encode([
|
$body = new StreamFactory()->createStream(json_encode([
|
||||||
'textId' => 99,
|
'textId' => 99,
|
||||||
'title' => 'Some Node',
|
'title' => 'Some Node',
|
||||||
'parentNodeId' => null,
|
'parentNodeId' => null,
|
||||||
]));
|
]));
|
||||||
$request = (new ServerRequestFactory())
|
$request = new ServerRequestFactory()
|
||||||
->createServerRequest('POST', 'http://localhost/api/nodes')
|
->createServerRequest('POST', 'http://localhost/api/nodes')
|
||||||
->withHeader('Content-Type', 'application/json')
|
->withHeader('Content-Type', 'application/json')
|
||||||
->withBody($body);
|
->withBody($body);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class TextControllerTest extends TestCase
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->textRepo = new FakeTextRepository;
|
$this->textRepo = new FakeTextRepository();
|
||||||
$this->textRepo->create(new CreateTextDto(
|
$this->textRepo->create(new CreateTextDto(
|
||||||
name: 'test text',
|
name: 'test text',
|
||||||
));
|
));
|
||||||
|
|
@ -56,7 +56,7 @@ class TextControllerTest extends TestCase
|
||||||
[
|
[
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'name' => 'test text 2',
|
'name' => 'test text 2',
|
||||||
]
|
],
|
||||||
]),
|
]),
|
||||||
$response->getBody()
|
$response->getBody()
|
||||||
);
|
);
|
||||||
|
|
@ -64,7 +64,7 @@ class TextControllerTest extends TestCase
|
||||||
|
|
||||||
public function test_create_text(): void
|
public function test_create_text(): void
|
||||||
{
|
{
|
||||||
$request = (new ServerRequestFactory())
|
$request = new ServerRequestFactory()
|
||||||
->createServerRequest('POST', 'http://localhost/texts')
|
->createServerRequest('POST', 'http://localhost/texts')
|
||||||
->withParsedBody(['name' => 'my new text']);
|
->withParsedBody(['name' => 'my new text']);
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ class TextControllerTest extends TestCase
|
||||||
new Response(),
|
new Response(),
|
||||||
new CreateText(
|
new CreateText(
|
||||||
$this->textRepo,
|
$this->textRepo,
|
||||||
new FakeNodeRepository,
|
new FakeNodeRepository(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue