Skip to content

Commit

Permalink
Integration Test
Browse files Browse the repository at this point in the history
To be sure that a new version of contentful client or any other
variables that might interfeer in the execution of this command doesn't
break it, we're adding an integration test that will hit the real
contentful API.

Signed-off-by: Airton Zanon <[email protected]>
  • Loading branch information
airtonzanon committed Feb 17, 2023
1 parent 3861bce commit 0fd8a30
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ jobs:
build:
name: CI
runs-on: ubuntu-latest
env:
contentful_space_id: ${{ secrets.CONTENTFUL_SPACE_ID }}
contentful_token: ${{ secrets.CONTENTFUL_TOKEN }}

strategy:
matrix:
Expand Down
7 changes: 3 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
verbose="true"
colors="true"
>
<php>
<env name="contentful_space_id" value="test-space-id" />
<env name="contentful_token" value="test-token123444" />
</php>
<testsuites>
<testsuite name="unit">
<directory>./tests/Unit</directory>
</testsuite>
<testsuite name="integration">
<directory>./tests/Integration</directory>
</testsuite>
</testsuites>
<coverage>
<include>
Expand Down
28 changes: 28 additions & 0 deletions tests/Integration/SculpinContentfulCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);

namespace AirtonZanon\SculpinContentfulBundle\Tests\Integration;

use AirtonZanon\SculpinContentfulBundle\Command\SculpinContentfulCommand;
use Contentful\Delivery\Client;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;

final class SculpinContentfulCommandTest extends TestCase
{
public function testExecuteSuccessScenario(): void {
$command = new SculpinContentfulCommand();

$contentfulSpaceId = getenv('contentful_space_id');
$contentfulToken = getenv('contentful_token');

$client = new Client($contentfulToken, $contentfulSpaceId);

$command->setContentfulClient($client);
$commandTester = new CommandTester($command);
$commandTester->execute([]);

$output = $commandTester->getDisplay();
self::assertStringContainsString("Created file", $output);
}
}

0 comments on commit 0fd8a30

Please sign in to comment.