-
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
Showing
5 changed files
with
542 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
tests/PullRequest/Application/CommandHandler/CheckTranslationsCommandHandlerTest.php
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,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\PullRequest\Application\CommandHandler; | ||
|
||
use App\PullRequest\Application\Command\CheckTranslationsCommand; | ||
use App\PullRequest\Application\CommandHandler\CheckTranslationsCommandHandler; | ||
use App\PullRequest\Domain\Aggregate\PullRequest\PullRequest; | ||
use App\PullRequest\Domain\Aggregate\PullRequest\PullRequestDiff; | ||
use App\PullRequest\Domain\Aggregate\PullRequest\PullRequestId; | ||
use App\PullRequest\Infrastructure\Adapter\InMemoryPullRequestRepository; | ||
use App\Shared\Infrastructure\Provider\TranslationsCatalogProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CheckTranslationsCommandHandlerTest extends TestCase | ||
{ | ||
private PullRequestId $prId; | ||
private PullRequest $pr; | ||
private InMemoryPullRequestRepository $prRepository; | ||
private TranslationsCatalogProvider $catalogProvider; | ||
private CheckTranslationsCommandHandler $checkTranslationsCommandHandler; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->prId = new PullRequestId('PrestaShop', 'PrestaShop', '30510'); | ||
$this->pr = PullRequest::create(id: $this->prId, labels: [], approvals: []); | ||
$prDiffContent = file_get_contents(__DIR__.'/../../../fixtures/30510.diff'); | ||
$this->prRepository = $this->createMock(InMemoryPullRequestRepository::class); | ||
$this->catalogProvider = $this->createMock(TranslationsCatalogProvider::class); | ||
$this->checkTranslationsCommandHandler = new CheckTranslationsCommandHandler($this->prRepository, $this->catalogProvider); | ||
|
||
$this->prRepository->method('find')->willReturn($this->pr); | ||
$this->prRepository->method('getDiff')->willReturn(PullRequestDiff::parseDiff($this->prId, (string) $prDiffContent)); | ||
} | ||
|
||
public function testHandleWithNewStrings(): void | ||
{ | ||
// @phpstan-ignore-next-line | ||
$this->catalogProvider->method('getTranslationsCatalog')->willReturn([]); | ||
|
||
$this->checkTranslationsCommandHandler->__invoke(new CheckTranslationsCommand( | ||
repositoryOwner: $this->prId->repositoryOwner, | ||
repositoryName: $this->prId->repositoryName, | ||
pullRequestNumber: $this->prId->pullRequestNumber, | ||
)); | ||
|
||
/** @var PullRequest $pr */ | ||
$pr = $this->prRepository->find($this->prId); | ||
|
||
$this->assertCount( | ||
1, | ||
array_filter( | ||
$pr->getLabels(), | ||
static fn (string $label) => 'Waiting for wording' === $label | ||
) | ||
); | ||
} | ||
|
||
public function testHandleWithoutNewStrings(): void | ||
{ | ||
// @phpstan-ignore-next-line | ||
$this->catalogProvider->method('getTranslationsCatalog')->willReturn([ | ||
'By deleting this image format, the theme will not be able to use it. This will result in a degraded experience on your front office.', | ||
'Delete the images linked to this image setting', | ||
'Are you sure you want to delete this image setting?', | ||
'Cancel', | ||
'Delete', | ||
]); | ||
|
||
$this->checkTranslationsCommandHandler->__invoke(new CheckTranslationsCommand( | ||
repositoryOwner: $this->prId->repositoryOwner, | ||
repositoryName: $this->prId->repositoryName, | ||
pullRequestNumber: $this->prId->pullRequestNumber, | ||
)); | ||
|
||
/** @var PullRequest $pr */ | ||
$pr = $this->prRepository->find($this->prId); | ||
|
||
$this->assertCount( | ||
0, | ||
array_filter( | ||
$pr->getLabels(), | ||
static fn (string $label) => 'Waiting for wording' === $label | ||
) | ||
); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
tests/PullRequest/Domain/Aggregate/PullRequest/PullRequestDiffTest.php
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,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\PullRequest\Domain\Aggregate\PullRequest; | ||
|
||
use App\PullRequest\Domain\Aggregate\PullRequest\PullRequestDiff; | ||
use App\PullRequest\Domain\Aggregate\PullRequest\PullRequestId; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
|
||
class PullRequestDiffTest extends KernelTestCase | ||
{ | ||
public function testParseDiff(): void | ||
{ | ||
$diffContent = file_get_contents(__DIR__.'/../../../../fixtures/35380.diff'); | ||
$pr = new PullRequestId('prestashop', 'prestashop', '35380'); | ||
$prDiff = PullRequestDiff::parseDiff($pr, $diffContent); // @phpstan-ignore-line | ||
|
||
$this->assertNotNull($prDiff); | ||
$this->assertEquals(3, count($prDiff->getFiles())); | ||
|
||
$files = [ | ||
'src/Adapter/Hosting/HostingInformation.php', | ||
'src/Adapter/System/SystemInformation.php', | ||
'src/PrestaShopBundle/Resources/views/Admin/Configure/AdvancedParameters/system_information.html.twig', | ||
]; | ||
|
||
foreach ($prDiff->getFiles() as $key => $file) { | ||
$this->assertEquals($files[$key], $file->getFileName()); | ||
} | ||
|
||
$this->assertStringContainsString('\'hostname\' => $this->hostingInformation->getHostname(),', | ||
$prDiff->getFiles()[1]->getHunks()[0]->getNew() | ||
); | ||
$this->assertStringNotContainsString('\'hostname\' => $this->hostingInformation->getHostname(),', | ||
$prDiff->getFiles()[1]->getHunks()[0]->getOld() | ||
); | ||
} | ||
|
||
public function testParseDiffWithEmptyDiff(): void | ||
{ | ||
$pr = new PullRequestId('prestashop', 'prestashop', 'ko'); | ||
$prDiff = PullRequestDiff::parseDiff($pr, ''); | ||
|
||
$this->assertNotNull($prDiff); | ||
$this->assertEquals(0, count($prDiff->getFiles())); | ||
} | ||
|
||
public function testParseDiffWithTranslations(): void | ||
{ | ||
$diffContent = file_get_contents(__DIR__.'/../../../../fixtures/30510.diff'); | ||
$pr = new PullRequestId('prestashop', 'prestashop', '30510'); | ||
$prDiff = PullRequestDiff::parseDiff($pr, $diffContent); // @phpstan-ignore-line | ||
|
||
$this->assertNotNull($prDiff); | ||
|
||
$translations = $prDiff->getTranslations(); | ||
|
||
$needles = [ | ||
'Admin.Design.Notification' => [ | ||
'By deleting this image format, the theme will not be able to use it. This will result in a degraded experience on your front office.', | ||
'Delete the images linked to this image setting', | ||
], | ||
'Admin.Design.Feature' => [ | ||
'Are you sure you want to delete this image setting?', | ||
], | ||
'Admin.Actions' => [ | ||
'Cancel', | ||
'Delete', | ||
], | ||
]; | ||
$this->assertEquals($needles, $translations); | ||
} | ||
} |
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
Oops, something went wrong.