Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/DomainTest.php
<?php | <?php | ||||
namespace Tests\Feature; | namespace Tests\Feature; | ||||
use App\Domain; | use App\Domain; | ||||
use App\Entitlement; | use App\Entitlement; | ||||
use App\Sku; | use App\Sku; | ||||
use App\User; | use App\User; | ||||
use Illuminate\Foundation\Testing\WithFaker; | use Illuminate\Foundation\Testing\WithFaker; | ||||
use Illuminate\Foundation\Testing\RefreshDatabase; | use Illuminate\Foundation\Testing\RefreshDatabase; | ||||
use Illuminate\Support\Facades\Queue; | use Illuminate\Support\Facades\Queue; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class DomainTest extends TestCase | class DomainTest extends TestCase | ||||
{ | { | ||||
public function setUp(): void | private $domains = [ | ||||
{ | |||||
parent::setUp(); | |||||
$domains = [ | |||||
'public-active.com', | 'public-active.com', | ||||
'gmail.com', | 'gmail.com', | ||||
'ci-success-cname.kolab.org', | 'ci-success-cname.kolab.org', | ||||
'ci-success-txt.kolab.org', | 'ci-success-txt.kolab.org', | ||||
'ci-failure-cname.kolab.org', | 'ci-failure-cname.kolab.org', | ||||
'ci-failure-txt.kolab.org', | 'ci-failure-txt.kolab.org', | ||||
'ci-failure-none.kolab.org', | 'ci-failure-none.kolab.org', | ||||
]; | ]; | ||||
Domain::whereIn('namespace', $domains)->delete(); | public function setUp(): void | ||||
{ | |||||
parent::setUp(); | |||||
Domain::withTrashed()->whereIn('namespace', $this->domains)->forceDelete(); | |||||
} | |||||
public function tearDown(): void | |||||
{ | |||||
Domain::whereIn('namespace', $this->domains)->delete(); | |||||
parent::tearDown(); | |||||
} | } | ||||
/** | /** | ||||
* Test domain creating jobs | * Test domain creating jobs | ||||
*/ | */ | ||||
public function testCreateJobs(): void | public function testCreateJobs(): void | ||||
{ | { | ||||
// Fake the queue, assert that no jobs were pushed... | // Fake the queue, assert that no jobs were pushed... | ||||
Queue::fake(); | Queue::fake(); | ||||
Queue::assertNothingPushed(); | Queue::assertNothingPushed(); | ||||
$domain = Domain::create([ | $domain = Domain::create([ | ||||
'namespace' => 'gmail.com', | 'namespace' => 'gmail.com', | ||||
'status' => Domain::STATUS_NEW, | 'status' => Domain::STATUS_NEW, | ||||
'type' => Domain::TYPE_EXTERNAL, | 'type' => Domain::TYPE_EXTERNAL, | ||||
]); | ]); | ||||
Queue::assertPushed(\App\Jobs\DomainCreate::class, 1); | Queue::assertPushed(\App\Jobs\DomainCreate::class, 1); | ||||
Queue::assertPushed(\App\Jobs\DomainCreate::class, function ($job) use ($domain) { | Queue::assertPushed(\App\Jobs\DomainCreate::class, function ($job) use ($domain) { | ||||
$job_domain = TestCase::getObjectProperty($job, 'domain'); | $job_domain = TestCase::getObjectProperty($job, 'domain'); | ||||
return $job_domain->id === $domain->id | return $job_domain->id === $domain->id | ||||
&& $job_domain->namespace === $domain->namespace; | && $job_domain->namespace === $domain->namespace; | ||||
}); | }); | ||||
/* | |||||
Queue::assertPushedWithChain(\App\Jobs\DomainCreate::class, [ | |||||
\App\Jobs\DomainVerify::class, | |||||
]); | |||||
*/ | |||||
/* | |||||
FIXME: Looks like we can't really do detailed assertions on chained jobs | |||||
Another thing to consider is if we maybe should run these jobs | |||||
independently (not chained) and make sure there's no race-condition | |||||
in status update | |||||
Queue::assertPushed(\App\Jobs\DomainVerify::class, 1); | $job = new \App\Jobs\DomainCreate($domain); | ||||
Queue::assertPushed(\App\Jobs\DomainVerify::class, function ($job) use ($domain) { | $job->handle(); | ||||
machniak: This test was supposed to test that the job has been created, that's it. The job execution is… | |||||
$job_domain = TestCase::getObjectProperty($job, 'domain'); | |||||
return $job_domain->id === $domain->id | |||||
&& $job_domain->namespace === $domain->namespace; | |||||
}); | |||||
*/ | |||||
} | } | ||||
/** | /** | ||||
* Tests getPublicDomains() method | * Tests getPublicDomains() method | ||||
*/ | */ | ||||
public function testGetPublicDomains(): void | public function testGetPublicDomains(): void | ||||
{ | { | ||||
$public_domains = Domain::getPublicDomains(); | $public_domains = Domain::getPublicDomains(); | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |
This test was supposed to test that the job has been created, that's it. The job execution is tested in Featuire/Jobs. What's the point in executing the job here if you don't check the result, anyway.