Skip to content

Commit

Permalink
move tests by feature
Browse files Browse the repository at this point in the history
  • Loading branch information
roman.dykyi committed May 15, 2021
1 parent b9f37a9 commit 4d6a557
Show file tree
Hide file tree
Showing 56 changed files with 4,381 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ script:
- cd docker && docker-compose -f docker-compose.test.yml run tests
after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover code/tests/coverage.clover
- php ocular.phar code-coverage:upload --format=php-clover code/coverage.clover
2 changes: 1 addition & 1 deletion code/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
###> qossmic/deptrac-shim ###
/.deptrac.cache
###< qossmic/deptrac-shim ###
tests/coverage.clover
coverage.clover
Empty file removed code/1
Empty file.
7 changes: 5 additions & 2 deletions code/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
"App\\Tests\\Crossword\\": "src/Crossword/tests/",
"App\\Tests\\Dictionary\\": "src/Dictionary/tests/",
"App\\Tests\\Game\\": "src/Game/tests/",
"App\\Tests\\SharedKernel\\": "src/SharedKernel/tests/"
}
},
"replace": {
Expand All @@ -74,7 +77,7 @@
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"phpunit": "phpunit --coverage-clover=tests/coverage.clover",
"phpunit": "phpunit --coverage-clover=coverage.clover",
"psalm": "psalm",
"ecs": "ecs check src",
"phpcs": "phpcs --standard=PSR12 src/",
Expand Down
16 changes: 14 additions & 2 deletions code/config/routes/annotations.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
controllers:
resource: ../../src/
controllers_game:
resource: ../../src/Game/UI
type: annotation

controllers_crossword:
resource: ../../src/Crossword/UI
type: annotation

controllers_dictionary:
resource: ../../src/Dictionary/UI
type: annotation

controllers_swagger:
resource: ../../src/Swagger/UI
type: annotation

kernel:
Expand Down
5 changes: 5 additions & 0 deletions code/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,24 @@ services:
resource: '../src/*'
exclude:
- '../src/SharedKernel/config/'
- '../src/SharedKernel/tests/'
- '../src/Swagger/config/'
- '../src/Swagger/tests/'
- '../src/Game/config/'
- '../src/Game/tests/'
- '../src/Game/Domain/Model/'
- '../src/Game/Domain/Dto/'
- '../src/Game/Domain/Events/DomainEventsSubscriber.php'
- '../src/Game/Infrastructure/Repository/DoctrineMigrations/'
- '../src/Game/UI/Web/'
- '../src/Crossword/UI/API/'
- '../src/Crossword/config/'
- '../src/Crossword/tests/'
- '../src/Crossword/Domain/Model/'
- '../src/Crossword/Domain/Dto/'
- '../src/Dictionary/UI/API/'
- '../src/Dictionary/config/'
- '../src/Dictionary/tests/'
- '../src/Dictionary/Domain/Model/'
- '../src/Dictionary/Domain/Dto/'
- '../src/Dictionary/Application/Service/WordsStoragePopulate.php'
Expand Down
4,206 changes: 4,206 additions & 0 deletions code/coverage.clover

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion code/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory suffix=".php">tests</directory>
<directory suffix=".php">src/Crossword/tests</directory>
<directory suffix=".php">src/Dictionary/tests</directory>
<directory suffix=".php">src/Game/tests</directory>
<directory suffix=".php">src/SharedKernel/tests</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 4 additions & 0 deletions code/psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
<file name="src/Crossword/tests/bootstrap.php" />
<file name="src/Dictionary/tests/bootstrap.php" />
<file name="src/Game/tests/bootstrap.php" />
<file name="src/SharedKernel/tests/bootstrap.php" />
</ignoreFiles>
</projectFiles>
</psalm>
1 change: 1 addition & 0 deletions code/src/Crossword/config/ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
'/src/Crossword/Infrastructure/Dao',
'/src/Crossword/Domain/Service/Scanner/RowYScanner.php',
'/src/Crossword/Domain/Service/Scanner/RowXScanner.php',
'/src/Crossword/tests',
];
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use App\Crossword\Domain\Messages\Message\GenerateCrosswordMessage;
use App\Crossword\Infrastructure\Adapter\Dictionary\InMemoryDictionaryAdapter;
use App\SharedKernel\Application\Response\API\SuccessApiResponse;
use App\Tests\CrosswordTestCase;
use App\Tests\Crossword\CrosswordTestCase;

/**
* @coversDefaultClass \App\Crossword\Application\Service\CrosswordGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use App\Crossword\Infrastructure\Cache\CacheItem;
use App\Crossword\Infrastructure\Cache\InMemoryClient;
use App\Crossword\Infrastructure\Repository\Redis\ReadCrosswordRepository;
use App\Tests\CrosswordTestCase;
use Psr\Log\NullLogger;
use App\Tests\Crossword\CrosswordTestCase;

/**
* @coversDefaultClass \App\Crossword\Application\Service\CrosswordReceiver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use App\Crossword\Domain\Dto\DictionaryLanguagesDto;
use App\Crossword\Infrastructure\Adapter\Dictionary\InMemoryDictionaryAdapter;
use App\SharedKernel\Application\Response\API\SuccessApiResponse;
use App\Tests\CrosswordTestCase;
use Psr\Log\NullLogger;
use App\Tests\Crossword\CrosswordTestCase;

/**
* @coversDefaultClass \App\Crossword\Application\Service\SupportedLanguages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Tests;
namespace App\Tests\Crossword;

use Faker\Factory;
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
use App\Crossword\Domain\Model\Coordinate;
use App\Crossword\Domain\Model\Line;
use App\Crossword\Domain\Model\Row;
use App\Crossword\Domain\Repository\PersistCrosswordRepositoryInterface;
use App\Crossword\Domain\Service\Constructor\ConstructorFactory;
use App\Crossword\Domain\Service\Constructor\ConstructorInterface;
use App\Crossword\Infrastructure\Cache\InMemoryClient;
use App\Crossword\Infrastructure\Repository\Redis\PersistCrosswordRepository;
use App\SharedKernel\Domain\Model\Word;
use App\Tests\CrosswordTestCase;
use App\Tests\Crossword\CrosswordTestCase;

/**
* @coversDefaultClass \App\Crossword\Domain\Messages\Handler\GenerateCrosswordMessageHandler
Expand All @@ -33,7 +32,7 @@ public function testGenerateCrosswordMessageHandler(): void
{
$cache = new InMemoryClient();

$row = new Row(new Cell(new Coordinate(1,1), null));
$row = new Row(new Cell(new Coordinate(1, 1), null));
$crosswordDto = new CrosswordDto(new LineDto(new Line($row), new Word('test', 'test test')));
$mockConstructor = $this->createMock(ConstructorInterface::class);
$mockConstructor->method('build')->willReturn($crosswordDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function testFillLetter(): void
$cells = $line->jsonSerialize();

self::assertSame($cells[0]['letter'], 'q');

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

declare(strict_types=1);

namespace App\Tests\Crossword\Domain\Service\Constructor;
namespace Tests\Crossword\Domain\Service\Constructor;

use App\Crossword\Domain\Enum\Type;
use App\Crossword\Domain\Service\Constructor\ConstructorFactory;
use App\Crossword\Domain\Service\Constructor\Figured\FiguredConstructor;
use App\Crossword\Domain\Service\Constructor\Normal\NormalConstructor;
use App\Crossword\Domain\Service\WordFinder;
use App\Crossword\Infrastructure\Adapter\Dictionary\InMemoryDictionaryAdapter;
use App\Tests\CrosswordTestCase;
use App\Tests\Crossword\CrosswordTestCase;
use Generator;
use Psr\Log\NullLogger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Tests\Crossword\Domain\Service\Constructor\Normal;
namespace Tests\Crossword\Domain\Service\Constructor\Normal;

use App\Crossword\Domain\Dto\DictionaryWordDto;
use App\Crossword\Domain\Service\Constructor\Normal\AttemptWordFinder;
Expand All @@ -11,7 +11,7 @@
use App\SharedKernel\Application\Response\API\SuccessApiResponse;
use App\SharedKernel\Domain\Model\Mask;
use App\SharedKernel\Domain\Model\Word;
use App\Tests\CrosswordTestCase;
use App\Tests\Crossword\CrosswordTestCase;
use Psr\Log\NullLogger;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use App\SharedKernel\Application\Response\API\FailedApiResponse;
use App\SharedKernel\Application\Response\API\SuccessApiResponse;
use App\SharedKernel\Domain\Model\Word;
use App\Tests\CrosswordTestCase;
use Psr\Log\NullLogger;
use App\Tests\Crossword\CrosswordTestCase;

/**
* @coversDefaultClass \App\Crossword\Domain\Service\WordFinder
Expand Down
11 changes: 11 additions & 0 deletions code/src/Crossword/tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__) . '/../../vendor/autoload.php';

if (file_exists(dirname(__DIR__) . '/../../config/bootstrap.php')) {
require dirname(__DIR__) . '/../../config/bootstrap.php';
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
(new Dotenv())->bootEnv(dirname(__DIR__) . '/../../.env');
}
1 change: 1 addition & 0 deletions code/src/Dictionary/config/ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
const DICTIONARY_SKIP_PATH = [
'/src/Dictionary/Infrastructure/Repository',
'/src/Dictionary/Infrastructure/Dao',
'/src/Dictionary/tests',
];
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace App\Tests\Dictionary\Application\Assert;

use App\Dictionary\Application\Assert\FileAssert;
use App\Tests\CrosswordTestCase;
use RuntimeException;
use App\Tests\Dictionary\DictionaryTestCase;

/**
* @coversDefaultClass \App\Dictionary\Application\Assert\FileAssert
*/
final class FileAssertTest extends CrosswordTestCase
final class FileAssertTest extends DictionaryTestCase
{
/**
* @covers ::assertFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use App\Dictionary\Application\Criteria\WordsStoragePopulateCriteria;
use App\Dictionary\Application\Service\WordsStoragePopulate;
use App\Dictionary\Infrastructure\FileReader\TextFileReader;
use App\Tests\CrosswordTestCase;
use Psr\Log\NullLogger;
use App\Tests\Dictionary\DictionaryTestCase;

/**
* @coversDefaultClass \App\Dictionary\Application\Service\WordsStoragePopulate
*/
final class WordsStoragePopulateTest extends CrosswordTestCase
final class WordsStoragePopulateTest extends DictionaryTestCase
{
private const WORD_LIST = ['test', 'search', 'date'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
use App\Dictionary\Application\Service\WordsStorageUpload;
use App\Dictionary\Domain\Messages\Message\SaveToStorageMessage;
use App\Dictionary\Infrastructure\FileReader\CsvFileReader;
use App\Tests\CrosswordTestCase;
use Psr\Log\NullLogger;
use App\Tests\Dictionary\DictionaryTestCase;

/**
* @coversDefaultClass \App\Dictionary\Application\Service\WordsStorageUpload
*/
final class WordsStorageUploadTest extends CrosswordTestCase
final class WordsStorageUploadTest extends DictionaryTestCase
{
/**
* @covers ::execute
Expand Down
58 changes: 58 additions & 0 deletions code/src/Dictionary/tests/DictionaryTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace App\Tests\Dictionary;

use Faker\Factory;
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;

abstract class DictionaryTestCase extends TestCase
{
protected function messageBusMock(): MessageBusInterface
{
return new class implements MessageBusInterface {
public function dispatch($message, array $stamps = []): Envelope
{
return new Envelope($message);
}
};
}

protected function messageBusMockWithConsecutive(
InvocationOrder $invocationRule,
$message = null
): MessageBusInterface {
if (null === $message) {
$messageBus = $this->createMock(MessageBusInterface::class);
$messageBus->expects($invocationRule)->method('dispatch');

return $messageBus;
}

$messageBus = $this->createMock(MessageBusInterface::class);
$messageBus->expects($invocationRule)
->method('dispatch')
->withConsecutive(
[
self::isInstanceOf(get_class($message)),
]
)
->willReturn(new Envelope($message));

return $messageBus;
}

protected function createTempFile(string $ext = '.tmp', array $data = []): string
{
$filePath = sys_get_temp_dir() . uniqid(Factory::create()->name, true) . $ext;
foreach ($data as $item) {
file_put_contents($filePath, $item . PHP_EOL, FILE_APPEND);
}

return $filePath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
use App\Dictionary\Domain\Messages\Message\SaveToStorageMessage;
use App\Dictionary\Domain\Messages\Message\SearchWordDefinitionMessage;
use App\Dictionary\Infrastructure\Gateway\InMemory\WordDefinitionApiGatewayInMemory;
use App\Tests\CrosswordTestCase;
use App\Tests\Dictionary\DictionaryTestCase;

/**
* @coversDefaultClass \App\Dictionary\Domain\Messages\Handler\SearchWordDefinitionMessageHandler
*/
final class SearchWordDefinitionMessageHandlerTest extends CrosswordTestCase
final class SearchWordDefinitionMessageHandlerTest extends DictionaryTestCase
{
/**
* @covers ::__invoke
Expand Down
11 changes: 11 additions & 0 deletions code/src/Dictionary/tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__) . '/../../vendor/autoload.php';

if (file_exists(dirname(__DIR__) . '/../../config/bootstrap.php')) {
require dirname(__DIR__) . '/../../config/bootstrap.php';
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
(new Dotenv())->bootEnv(dirname(__DIR__) . '/../../.env');
}
1 change: 1 addition & 0 deletions code/src/Game/config/ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
const GAME_SKIP_PATH = [
'/src/Game/Infrastructure/Repository',
'/src/Game/Infrastructure/Dao',
'/src/Game/tests',
];
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use App\Game\Domain\Model\PlayerId;
use App\Game\Infrastructure\Encoder\Base64Encoder;
use App\Game\Infrastructure\Repository\InMemory\InMemoryPlayerRepository;
use App\Tests\GameTestCase;
use App\Tests\Game\GameTestCase;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

Expand Down
Loading

0 comments on commit 4d6a557

Please sign in to comment.