Skip to content

Commit

Permalink
Fix tests with post request
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Jan 16, 2022
1 parent e887c8c commit c630642
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
5 changes: 3 additions & 2 deletions tests/Controller/ImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ public function testImportSuccess(): void
$this->env = Environment::mock([
'SCRIPT_NAME' => 'index.php',
'PATH_INFO' => '/',
'slim.input' => json_encode($data),
]);

$request = $this->createJsonPostRequest($data);

$searcher = $this->searcher->truncate();
$before = $searcher->getForUrl('/things', []);
$this->assertEmpty($before['results']);

$this->import->import($this->request);
$this->import->import($request);

$after = $searcher->getForUrl('/things', []);
$this->assertNotEmpty($after['results']);
Expand Down
7 changes: 3 additions & 4 deletions tests/Controller/RunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,14 @@ public function testDeleteSubmit(): void
'REQUEST_METHOD' => 'POST',
'SCRIPT_NAME' => 'index.php',
'PATH_INFO' => '/run/delete',
'slim.request.form_hash' => [
'id' => 'aaaaaaaaaaaaaaaaaaaaaaaa',
],
]);

$request = $this->createPostRequest(['id' => 'aaaaaaaaaaaaaaaaaaaaaaaa']);

$result = $searcher->getAll(new SearchOptions());
$count = count($result['results']);

$this->runs->deleteSubmit($this->request);
$this->runs->deleteSubmit($request);

$result = $searcher->getAll(new SearchOptions());
$this->assertCount($count - 1, $result['results']);
Expand Down
19 changes: 10 additions & 9 deletions tests/Controller/WatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public function testGet(): void
public function testPostAdd(): void
{
$this->searcher->truncateWatches();
$_POST = [
$request = $this->createPostRequest([
'watch' => [
['name' => 'strlen'],
['name' => 'strpos'],
],
];
]);

$this->watches->post($this->request);
$this->watches->post($request);
$result = $this->searcher->getAllWatches();

$this->assertCount(2, $result);
Expand All @@ -50,12 +50,12 @@ public function testPostModify(): void
$searcher->saveWatch(['name' => 'strlen']);
$saved = $searcher->getAllWatches();

$_POST = [
$request = $this->createPostRequest([
'watch' => [
['name' => 'strpos', '_id' => $saved[0]['_id']],
],
];
$this->watches->post($this->request);
]);
$this->watches->post($request);
$result = $searcher->getAllWatches();

$this->assertCount(1, $result);
Expand All @@ -68,12 +68,13 @@ public function testPostDelete(): void
$this->searcher->saveWatch(['name' => 'strlen']);
$saved = $this->searcher->getAllWatches();

$_POST = [
$request = $this->createPostRequest([
'watch' => [
['removed' => 1, 'name' => 'strpos', '_id' => $saved[0]['_id']],
],
];
$this->watches->post($this->request);
]);

$this->watches->post($request);
$result = $this->searcher->getAllWatches();

$this->assertCount(0, $result);
Expand Down

0 comments on commit c630642

Please sign in to comment.