forked from biig-io/Melodiia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request biig-io#18 from swagindustries/feature/test-app
- Loading branch information
Showing
25 changed files
with
545 additions
and
39 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,29 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
|
||
# Matches multiple files with brace expansion notation | ||
# Set default charset | ||
[*.{js,ts}] | ||
indent_size = 2 | ||
|
||
# Tab indentation (no size specified) | ||
[Makefile] | ||
indent_style = tab | ||
|
||
[*.md] | ||
max_line_length = off | ||
trim_trailing_whitespace = false | ||
|
||
[*.{yaml,yml,feature}] | ||
indent_size = 2 |
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 |
---|---|---|
@@ -1,49 +1,63 @@ | ||
name: Test suite | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
schedule: | ||
- cron: '0 0 * * *' | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
schedule: | ||
- cron: '0 0 * * *' | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
unit-test: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
php: [7.4] | ||
strategy: | ||
matrix: | ||
php: [7.4] | ||
|
||
steps: | ||
- name: Setup PHP | ||
run: | | ||
sudo update-alternatives --set php /usr/bin/php${{ matrix.php }} | ||
echo "date.timezone=UTC" >> /tmp/timezone.ini | ||
sudo mv /tmp/timezone.ini /etc/php/${{ matrix.php }}/cli/conf.d/timezone.ini | ||
echo ${{ matrix.php }} > .php-version | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: actions/checkout@v2 | ||
- uses: actions/cache@v2 | ||
id: cache-composer | ||
with: | ||
path: ~/.composer/cache | ||
key: composer-php-${{ matrix.php }}-${{ github.sha }} | ||
restore-keys: composer-php-${{ matrix.php }}- | ||
|
||
- uses: actions/cache@v1 | ||
id: cache-composer | ||
with: | ||
path: /home/runner/.composer/cache | ||
key: composer-php:${{ matrix.php }}-${{ github.sha }} | ||
restore-keys: composer-php:${{ matrix.php }}- | ||
- name: Valid composer.json | ||
run: make test.composer | ||
|
||
- run: mkdir -p /home/runner/.composer/cache | ||
if: steps.cache-composer.outputs.cache-hit != 'true' | ||
- name: Install dependencies | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
|
||
- name: Valid composer.json | ||
run: make test.composer | ||
- name: Run PHP CS Fixer | ||
run: make test.phpcs | ||
|
||
- name: Install dependencies | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
- name: Run PHPUnit tests | ||
run: make test.phpunit | ||
|
||
- name: Run PHP CS Fixer | ||
run: make test.phpcs | ||
functional-test: | ||
runs-on: ubuntu-latest | ||
|
||
- name: Run PHPUnit tests | ||
run: make test.phpunit | ||
strategy: | ||
matrix: | ||
php: [7.4] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: actions/cache@v2 | ||
id: cache-composer | ||
with: | ||
path: ~/.composer/cache | ||
key: composer-php-${{ matrix.php }}-${{ github.sha }} | ||
restore-keys: composer-php-${{ matrix.php }}- | ||
|
||
|
||
- name: Install dependencies | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
|
||
- name: Run Behat tests | ||
run: make test.behat |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
composer.lock | ||
vendor | ||
.php_cs.cache | ||
tests/TestApplication/var |
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
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
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
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,11 @@ | ||
default: | ||
suites: | ||
default: | ||
contexts: | ||
- SwagIndustries\Melodiia\Tests\Behat\Context\BasicsContext | ||
- SwagIndustries\Melodiia\Tests\Behat\Context\TodoContext | ||
extensions: | ||
FriendsOfBehat\SymfonyExtension: | ||
bootstrap: tests/TestApplication/config/bootstrap.php | ||
kernel: | ||
class: TestApplication\Kernel |
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
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,61 @@ | ||
Feature: | ||
In order to create, read, update and delete data using the API | ||
As a client software | ||
I should be able use standard REST CRUD actions with todos | ||
|
||
Scenario: list some todo | ||
Given there are some todos | ||
When I make a GET request on "/todos" | ||
Then I should retrieve: | ||
""" | ||
{ | ||
"meta": { | ||
"totalPages": 1, | ||
"totalResults": 3, | ||
"currentPage": 1, | ||
"maxPerPage": 30 | ||
}, | ||
"links": { | ||
"prev": null, | ||
"next": null, | ||
"last": "http://localhost/todos", | ||
"first": "http://localhost/todos" | ||
}, | ||
"data": [ | ||
{ | ||
"id": 1, | ||
"content": "foo" | ||
}, | ||
{ | ||
"id": 2, | ||
"content": "bar" | ||
}, | ||
{ | ||
"id": 3, | ||
"content": "baz" | ||
} | ||
] | ||
} | ||
""" | ||
|
||
Scenario: create a todo and get it | ||
Given I make a "POST" request on "/todos" with the content: | ||
""" | ||
{ | ||
"content": "hello" | ||
} | ||
""" | ||
And the last response contains: | ||
""" | ||
{ | ||
"id": "1" | ||
} | ||
""" | ||
When I make a GET request on "/todos/1" | ||
Then I should retrieve: | ||
""" | ||
{ | ||
"id": 1, | ||
"content": "hello" | ||
} | ||
""" |
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
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 SwagIndustries\Melodiia\Tests\Behat\Context; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Faker\Factory; | ||
use Faker\Generator; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
|
||
abstract class AbstractContext implements Context | ||
{ | ||
private KernelInterface $kernel; | ||
protected Generator $faker; | ||
|
||
public function __construct(KernelInterface $kernel) | ||
{ | ||
$this->kernel = $kernel; | ||
$this->faker = Factory::create(); | ||
} | ||
|
||
protected function getContainer(): ContainerInterface | ||
{ | ||
return $this->kernel->getContainer(); | ||
} | ||
} |
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,69 @@ | ||
<?php | ||
|
||
namespace SwagIndustries\Melodiia\Tests\Behat\Context; | ||
|
||
use Behat\Gherkin\Node\PyStringNode; | ||
use Doctrine\ORM\Tools\SchemaTool; | ||
|
||
class BasicsContext extends AbstractContext | ||
{ | ||
private $response; | ||
|
||
/** | ||
* @When I make a GET request on :uri | ||
* @Given I make a :verb request on :uri with the content: | ||
*/ | ||
public function iMakeARequestOn($uri, $verb = 'GET', PyStringNode $content = null) | ||
{ | ||
$client = $this->getContainer()->get('test.client'); | ||
|
||
if ('GET' === $verb) { | ||
$client->request($verb, $uri); | ||
$this->response = $client->getResponse(); | ||
|
||
return; | ||
} | ||
|
||
if (empty($content)) { | ||
throw new \Exception(sprintf('Cannot process request "%s" with no content.', $verb)); | ||
} | ||
|
||
// Just validate json | ||
json_decode($content->getRaw(), true, 512, JSON_THROW_ON_ERROR); | ||
|
||
$client->request($verb, $uri, [], [], [], $content); | ||
$this->response = $client->getResponse(); | ||
} | ||
|
||
/** | ||
* @Then I should retrieve: | ||
* @Given the last response contains: | ||
*/ | ||
public function iShouldRetrieve(PyStringNode $string) | ||
{ | ||
$json = $this->response->getContent(); | ||
$expected = \json_encode(\json_decode($string->getRaw(), true, 512, JSON_THROW_ON_ERROR)); | ||
|
||
if ($json !== $expected) { | ||
if (json_decode($json)) { | ||
echo "Expected: $expected\n"; | ||
echo "Actual: $json\n"; | ||
} | ||
|
||
throw new \Exception('Expected request result does not match actual result.'); | ||
} | ||
} | ||
|
||
/** | ||
* @BeforeScenario | ||
*/ | ||
public function resetDb() | ||
{ | ||
@unlink(dirname(__DIR__) . '/../TestApplication/var/data.db'); | ||
|
||
$entityManager = $this->getContainer()->get('doctrine')->getManager(); | ||
$metadatas = $entityManager->getMetadataFactory()->getAllMetadata(); | ||
$schemaTool = new SchemaTool($entityManager); | ||
$schemaTool->createSchema($metadatas); | ||
} | ||
} |
Oops, something went wrong.