Skip to content

Commit

Permalink
Use Paratest in GitHub Action (#1346)
Browse files Browse the repository at this point in the history
Co-authored-by: Melroy van den Berg <[email protected]>
Co-authored-by: BentiGorlich <[email protected]>
  • Loading branch information
3 people authored Jan 25, 2025
1 parent 00ef4a5 commit 8acf984
Show file tree
Hide file tree
Showing 24 changed files with 79 additions and 7 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,27 @@ jobs:
DATABASE_PORT: 5432
REDIS_HOST: valkey
REDIS_PORT: 6379
run: php bin/phpunit tests/Unit
run: php vendor/bin/paratest --passthru-php="'-d' 'memory_limit=192M'" tests/Unit

- name: Run integration tests
- name: Run non thread safe integration tests
env:
COMPOSER_CACHE_DIR: ${{ steps.composer-cache.outputs.dir }}
SYMFONY_DEPRECATIONS_HELPER: disabled
DATABASE_HOST: postgres
DATABASE_PORT: 5432
REDIS_HOST: valkey
REDIS_PORT: 6379
run: php bin/phpunit tests/Functional
run: php vendor/bin/phpunit tests/Functional --group NonThreadSafe

- name: Run thread safe integration tests
env:
COMPOSER_CACHE_DIR: ${{ steps.composer-cache.outputs.dir }}
SYMFONY_DEPRECATIONS_HELPER: disabled
DATABASE_HOST: postgres
DATABASE_PORT: 5432
REDIS_HOST: valkey
REDIS_PORT: 6379
run: php vendor/bin/paratest --passthru-php="'-d' 'memory_limit=192M'" tests/Functional --exclude-group NonThreadSafe
services:
postgres:
# Docker Hub image
Expand Down
3 changes: 3 additions & 0 deletions tests/Functional/Controller/Api/Domain/DomainBlockApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Api\Domain;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class DomainBlockApiTest extends WebTestCase
{
Expand All @@ -29,6 +30,7 @@ public function testApiCannotBlockDomainWithoutScope()
self::assertResponseStatusCodeSame(403);
}

#[Group(name: 'NonThreadSafe')]
public function testApiCanBlockDomain()
{
$domain = $this->getEntryByTitle('Test link to a domain', 'https://example.com')->domain;
Expand Down Expand Up @@ -89,6 +91,7 @@ public function testApiCannotUnblockDomainWithoutScope()
self::assertResponseStatusCodeSame(403);
}

#[Group(name: 'NonThreadSafe')]
public function testApiCanUnblockDomain()
{
$user = $this->getUserByUsername('JohnDoe');
Expand Down
2 changes: 2 additions & 0 deletions tests/Functional/Controller/Api/Entry/EntryUpdateApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Api\Entry;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class EntryUpdateApiTest extends WebTestCase
{
Expand Down Expand Up @@ -370,6 +371,7 @@ public function testApiCanUpdateOtherUsersImageEntry(): void
self::assertResponseStatusCodeSame(403);
}

#[Group(name: 'NonThreadSafe')]
public function testApiCanUpdateImageEntry(): void
{
$user = $this->getUserByUsername('user');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\DTO\ModeratorDto;
use App\Tests\Functional\Controller\Api\Magazine\MagazineRetrieveApiTest;
use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class MagazineDeleteIconApiTest extends WebTestCase
Expand Down Expand Up @@ -63,6 +64,7 @@ public function testApiModCannotDeleteMagazineIcon(): void
self::assertResponseStatusCodeSame(403);
}

#[Group(name: 'NonThreadSafe')]
public function testApiCanDeleteMagazineIcon(): void
{
$user = $this->getUserByUsername('JohnDoe');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\DTO\ReportDto;
use App\Tests\Functional\Controller\Api\Magazine\MagazineRetrieveApiTest;
use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class MagazineActionReportsApiTest extends WebTestCase
{
Expand Down Expand Up @@ -118,6 +119,7 @@ public function testApiCannotRejectReportIfNotMod(): void
self::assertResponseStatusCodeSame(403);
}

#[Group(name: 'NonThreadSafe')]
public function testApiCanAcceptReport(): void
{
$user = $this->getUserByUsername('JohnDoe');
Expand Down Expand Up @@ -155,8 +157,8 @@ public function testApiCanAcceptReport(): void
self::assertEquals($entry->body, $jsonData['subject']['body']);
self::assertEquals('approved', $jsonData['status']);
self::assertSame(1, $jsonData['weight']);
self::assertSame($report->createdAt->getTimestamp(), \DateTimeImmutable::createFromFormat(\DateTimeImmutable::ATOM, $jsonData['createdAt'])->getTimestamp());
self::assertSame($consideredAt->getTimestamp(), \DateTimeImmutable::createFromFormat(\DateTimeImmutable::ATOM, $jsonData['consideredAt'])->getTimestamp());
self::assertGreaterThanOrEqual($report->createdAt->getTimestamp(), \DateTimeImmutable::createFromFormat(\DateTimeImmutable::ATOM, $jsonData['createdAt'])->getTimestamp());
self::assertGreaterThanOrEqual($consideredAt->getTimestamp(), \DateTimeImmutable::createFromFormat(\DateTimeImmutable::ATOM, $jsonData['consideredAt'])->getTimestamp());
self::assertNotNull($jsonData['consideredBy']);
self::assertArrayKeysMatch(self::USER_SMALL_RESPONSE_KEYS, $jsonData['consideredBy']);
self::assertSame($user->getId(), $jsonData['consideredBy']['userId']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Api\OAuth2;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class OAuth2ClientApiTest extends WebTestCase
Expand Down Expand Up @@ -130,6 +131,7 @@ public function testApiCanCreateWorkingPublicClient(): void
self::assertIsArray($jsonData);
}

#[Group(name: 'NonThreadSafe')]
public function testApiCanCreateWorkingClientWithImage(): void
{
$requestData = [
Expand Down
2 changes: 2 additions & 0 deletions tests/Functional/Controller/Api/Post/PostUpdateApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Api\Post;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class PostUpdateApiTest extends WebTestCase
{
Expand Down Expand Up @@ -188,6 +189,7 @@ public function testApiCannotUpdateOtherUsersImagePost(): void
self::assertResponseStatusCodeSame(403);
}

#[Group(name: 'NonThreadSafe')]
public function testApiCanUpdateImagePost(): void
{
$user = $this->getUserByUsername('user');
Expand Down
3 changes: 3 additions & 0 deletions tests/Functional/Controller/Api/User/UserBlockApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Api\User;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class UserBlockApiTest extends WebTestCase
{
Expand Down Expand Up @@ -32,6 +33,7 @@ public function testApiCannotUnblockUserWithoutScope(): void
self::assertResponseStatusCodeSame(403);
}

#[Group(name: 'NonThreadSafe')]
public function testApiCanBlockUser(): void
{
self::createOAuth2AuthCodeClient();
Expand Down Expand Up @@ -67,6 +69,7 @@ public function testApiCanBlockUser(): void
self::assertTrue($jsonData['isBlockedByUser']);
}

#[Group(name: 'NonThreadSafe')]
public function testApiCanUnblockUser(): void
{
self::createOAuth2AuthCodeClient();
Expand Down
2 changes: 2 additions & 0 deletions tests/Functional/Controller/Api/User/UserFollowApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Api\User;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class UserFollowApiTest extends WebTestCase
{
Expand Down Expand Up @@ -32,6 +33,7 @@ public function testApiCannotUnfollowUserWithoutScope(): void
self::assertResponseStatusCodeSame(403);
}

#[Group(name: 'NonThreadSafe')]
public function testApiCanFollowUser(): void
{
self::createOAuth2AuthCodeClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace App\Tests\Functional\Controller\Domain;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class DomainBlockControllerTest extends WebTestCase
{
#[Group(name: 'NonThreadSafe')]
public function testUserCanBlockAndUnblockDomain(): void
{
$entry = $this->createEntry(
Expand All @@ -34,6 +36,7 @@ public function testUserCanBlockAndUnblockDomain(): void
$this->assertSelectorNotExists('#sidebar form[name=domain_block] .active');
}

#[Group(name: 'NonThreadSafe')]
public function testXmlUserCanBlockDomain(): void
{
$entry = $this->createEntry(
Expand All @@ -54,6 +57,7 @@ public function testXmlUserCanBlockDomain(): void
$this->assertStringContainsString('active', $this->client->getResponse()->getContent());
}

#[Group(name: 'NonThreadSafe')]
public function testXmlUserCanUnblockDomain(): void
{
$entry = $this->createEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Entry\Comment;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class EntryCommentCreateControllerTest extends WebTestCase
{
Expand Down Expand Up @@ -36,6 +37,7 @@ public function testUserCanCreateEntryComment(): void
$this->assertSelectorTextContains('#main blockquote', 'test comment 1');
}

#[Group(name: 'NonThreadSafe')]
public function testUserCanCreateEntryCommentWithImage(): void
{
$this->client->loginUser($this->getUserByUsername('JohnDoe'));
Expand All @@ -61,6 +63,7 @@ public function testUserCanCreateEntryCommentWithImage(): void
$_FILES = [];
}

#[Group(name: 'NonThreadSafe')]
public function testUserCanReplyEntryComment(): void
{
$comment = $this->createEntryComment(
Expand Down Expand Up @@ -90,6 +93,7 @@ public function testUserCanReplyEntryComment(): void
$this->assertEquals(2, $crawler->filter('#main blockquote')->count());
}

#[Group(name: 'NonThreadSafe')]
public function testUserCantCreateInvalidEntryComment(): void
{
$this->client->loginUser($this->getUserByUsername('JohnDoe'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Entry\Comment;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class EntryCommentEditControllerTest extends WebTestCase
{
Expand Down Expand Up @@ -36,6 +37,7 @@ public function testAuthorCanEditOwnEntryComment(): void
$this->assertSelectorTextContains('#main .entry-comment', 'test comment 2 body');
}

#[Group(name: 'NonThreadSafe')]
public function testAuthorCanEditOwnEntryCommentWithImage(): void
{
$this->client->loginUser($this->getUserByUsername('JohnDoe'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Entry;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class EntryCreateControllerTest extends WebTestCase
{
Expand Down Expand Up @@ -90,6 +91,7 @@ public function testUserCanCreateEntryPhoto()
$this->assertSelectorExists('form[name=entry_image]');
}

#[Group(name: 'NonThreadSafe')]
public function testUserCanCreateEntryPhotoFromMagazinePage()
{
$this->client->loginUser($this->getUserByUsername('user'));
Expand Down
2 changes: 2 additions & 0 deletions tests/Functional/Controller/Entry/EntryEditControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Entry;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class EntryEditControllerTest extends WebTestCase
{
Expand Down Expand Up @@ -65,6 +66,7 @@ public function testAuthorCanEditOwnEntryArticle(): void
$this->assertSelectorTextContains('#main .entry .entry__body', 'test entry 2 body');
}

#[Group(name: 'NonThreadSafe')]
public function testAuthorCanEditOwnEntryImage(): void
{
$this->client->loginUser($this->getUserByUsername('JohnDoe'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public function testXmlRootPageIsFrontPage(): void
$this->client->setServerParameter('HTTP_X-Requested-With', 'XMLHttpRequest');
$this->client->request('GET', '/');

$root_content = $this->clearTokens($this->client->getResponse()->getContent());
$root_content = self::removeTimeElements($this->clearTokens($this->client->getResponse()->getContent()));

$this->client->request('GET', '/all');
$frontContent = self::removeTimeElements($this->clearTokens($this->client->getResponse()->getContent()));

$this->assertSame($root_content, $this->clearTokens($this->client->getResponse()->getContent()));
$this->assertSame($root_content, $frontContent);
}

public function testFrontPage(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Post\Comment;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class PostCommentCreateControllerTest extends WebTestCase
{
Expand Down Expand Up @@ -36,6 +37,7 @@ public function testUserCanCreatePostComment(): void
$this->assertSelectorTextContains('#comments .content', 'test comment 1');
}

#[Group(name: 'NonThreadSafe')]
public function testUserCanCreatePostCommentWithImage(): void
{
$this->client->loginUser($this->getUserByUsername('JohnDoe'));
Expand All @@ -61,6 +63,7 @@ public function testUserCanCreatePostCommentWithImage(): void
$_FILES = [];
}

#[Group(name: 'NonThreadSafe')]
public function testUserCannotCreateInvalidPostComment(): void
{
$this->client->loginUser($this->getUserByUsername('JohnDoe'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Post\Comment;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class PostCommentEditControllerTest extends WebTestCase
{
Expand Down Expand Up @@ -35,6 +36,7 @@ public function testAuthorCanEditOwnPostComment(): void
$this->assertSelectorTextContains('#main .post-comment', 'test comment 2 body');
}

#[Group(name: 'NonThreadSafe')]
public function testAuthorCanEditOwnPostCommentWithImage(): void
{
$this->client->loginUser($this->getUserByUsername('JohnDoe'));
Expand Down
4 changes: 4 additions & 0 deletions tests/Functional/Controller/Post/PostCreateControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Post;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class PostCreateControllerTest extends WebTestCase
{
Expand Down Expand Up @@ -36,6 +37,7 @@ public function testUserCanCreatePost(): void
$this->assertSelectorTextContains('#content .post', 'test post 1');
}

#[Group(name: 'NonThreadSafe')]
public function testUserCanCreatePostWithImage(): void
{
$this->client->loginUser($this->getUserByUsername('JohnDoe'));
Expand All @@ -61,6 +63,7 @@ public function testUserCanCreatePostWithImage(): void
$_FILES = [];
}

#[Group(name: 'NonThreadSafe')]
public function testUserCannotCreateInvalidPost(): void
{
$this->client->loginUser($this->getUserByUsername('JohnDoe'));
Expand Down Expand Up @@ -104,6 +107,7 @@ public function testCreatedPostIsMarkedAsForAdults(): void
$this->assertSelectorTextContains('blockquote header .danger', '18+');
}

#[Group(name: 'NonThreadSafe')]
public function testPostCreatedInAdultMagazineIsAutomaticallyMarkedAsForAdults(): void
{
$this->client->loginUser($this->getUserByUsername('JohnDoe', hideAdult: false));
Expand Down
2 changes: 2 additions & 0 deletions tests/Functional/Controller/Post/PostEditControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Tests\Functional\Controller\Post;

use App\Tests\WebTestCase;
use PHPUnit\Framework\Attributes\Group;

class PostEditControllerTest extends WebTestCase
{
Expand Down Expand Up @@ -34,6 +35,7 @@ public function testAuthorCanEditOwnPost(): void
$this->assertSelectorTextContains('#main .post .content', 'test post 2 body');
}

#[Group(name: 'NonThreadSafe')]
public function testAuthorCanEditOwnPostWithImage(): void
{
$this->client->loginUser($this->getUserByUsername('JohnDoe'));
Expand Down
Loading

0 comments on commit 8acf984

Please sign in to comment.