-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0a9650
commit ea084ca
Showing
5 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace PhpSchool\PhpWorkshop\Exercise\Scenario; | ||
|
||
use Psr\Http\Message\RequestInterface; | ||
|
||
class CgiScenario extends ExerciseScenario | ||
{ | ||
/** | ||
* @var array<RequestInterface> | ||
*/ | ||
private array $executions = []; | ||
|
||
public function withExecution(RequestInterface $request): self | ||
{ | ||
$this->executions[] = $request; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return array<RequestInterface> | ||
*/ | ||
public function getExecutions(): array | ||
{ | ||
return $this->executions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace PhpSchool\PhpWorkshop\Exercise\Scenario; | ||
|
||
use PhpSchool\PhpWorkshop\Utils\Collection; | ||
|
||
class CliScenario extends ExerciseScenario | ||
{ | ||
/** | ||
* @var array<Collection<int, string>> | ||
*/ | ||
private array $executions = []; | ||
|
||
/** | ||
* @param array<string> $args | ||
*/ | ||
public function withExecution(array $args = []): static | ||
{ | ||
$this->executions[] = new Collection($args); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return array<Collection<int, string>> | ||
*/ | ||
public function getExecutions(): array | ||
{ | ||
return $this->executions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace PhpSchool\PhpWorkshop\Exercise\Scenario; | ||
|
||
abstract class ExerciseScenario | ||
{ | ||
/** | ||
* @var array<string, string> | ||
*/ | ||
private array $files = []; | ||
|
||
public function withFile(string $relativeFileName, string $content): static | ||
{ | ||
$this->files[$relativeFileName] = $content; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
public function getFiles(): array | ||
{ | ||
return $this->files; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace PhpSchool\PhpWorkshopTest\Exercise\Scenario; | ||
|
||
use PhpSchool\PhpWorkshop\Exercise\Scenario\CgiScenario; | ||
use PhpSchool\PhpWorkshop\Utils\Collection; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
class CgiScenarioTest extends TestCase | ||
{ | ||
public function testScenario(): void | ||
{ | ||
$requestOne = $this->createMock(RequestInterface::class); | ||
$requestTwo = $this->createMock(RequestInterface::class); | ||
|
||
$scenario = (new CgiScenario()) | ||
->withFile('file1.txt', 'content1') | ||
->withFile('file2.txt', 'content2') | ||
->withExecution($requestOne) | ||
->withExecution($requestTwo); | ||
|
||
static::assertEquals( | ||
[ | ||
'file1.txt' => 'content1', | ||
'file2.txt' => 'content2', | ||
], | ||
$scenario->getFiles() | ||
); | ||
|
||
static::assertEquals( | ||
[ | ||
$requestOne, | ||
$requestTwo | ||
], | ||
$scenario->getExecutions() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace PhpSchool\PhpWorkshopTest\Exercise\Scenario; | ||
|
||
use PhpSchool\PhpWorkshop\Exercise\Scenario\CliScenario; | ||
use PhpSchool\PhpWorkshop\Utils\Collection; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CliScenarioTest extends TestCase | ||
{ | ||
public function testScenario(): void | ||
{ | ||
$scenario = (new CliScenario()) | ||
->withFile('file1.txt', 'content1') | ||
->withFile('file2.txt', 'content2') | ||
->withExecution(['arg1', 'arg2']) | ||
->withExecution(['arg3', 'arg4']); | ||
|
||
static::assertEquals( | ||
[ | ||
'file1.txt' => 'content1', | ||
'file2.txt' => 'content2', | ||
], | ||
$scenario->getFiles() | ||
); | ||
|
||
static::assertEquals( | ||
[ | ||
['arg1', 'arg2'], | ||
['arg3', 'arg4'], | ||
], | ||
array_map( | ||
fn (Collection $collection) => $collection->getArrayCopy(), | ||
$scenario->getExecutions() | ||
) | ||
); | ||
} | ||
} |