Skip to content

Commit

Permalink
Add cleanup logic for glossary tests which use the shared glossary AP…
Browse files Browse the repository at this point in the history
…I as resource.
  • Loading branch information
sathielemann committed Nov 8, 2021
1 parent 937c77d commit bbf9385
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tests/integration/GlossaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace BabyMarkt\DeepL\integration;

use BabyMarkt\DeepL\DeepL;
use BabyMarkt\DeepL\Glossary;
use DateTime;
use PHPUnit\Framework\TestCase;

class GlossaryTest extends TestCase
Expand Down Expand Up @@ -37,8 +37,19 @@ public static function tearDownAfterClass(): void

$glossariesResponse = $glossaryAPI->listGlossaries();

$fiveMinutesAgo = new DateTime(
date(
'Y-m-d H:i:s',
time() - 60 * 5
)
);

// Cleanup old test fixtures in the deepl API. The 5 minute threashold is used to prevent parallel tests
// execution intervention on the CI server.
foreach ($glossariesResponse['glossaries'] as $glossary) {
$glossaryAPI->deleteGlossary($glossary['glossary_id']);
if (new DateTime($glossary['creation_time']) < $fiveMinutesAgo) {
$glossaryAPI->deleteGlossary($glossary['glossary_id']);
}
}
}

Expand Down

0 comments on commit bbf9385

Please sign in to comment.