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(); | |||||
foreach ($this->domains as $domain) { | |||||
$this->deleteTestDomain($domain); | |||||
} | |||||
} | |||||
public function tearDown(): void | |||||
{ | |||||
foreach ($this->domains as $domain) { | |||||
$this->deleteTestDomain($domain); | |||||
} | |||||
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) { | |||||
$job_domain = TestCase::getObjectProperty($job, 'domain'); | |||||
return $job_domain->id === $domain->id | Queue::assertPushed( | ||||
machniak: This test was supposed to test that the job has been created, that's it. The job execution is… | |||||
&& $job_domain->namespace === $domain->namespace; | \App\Jobs\DomainCreate::class, | ||||
}); | function ($job) use ($domain) { | ||||
/* | |||||
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); | |||||
Queue::assertPushed(\App\Jobs\DomainVerify::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; | ||||
}); | } | ||||
*/ | ); | ||||
$job = new \App\Jobs\DomainCreate($domain); | |||||
$job->handle(); | |||||
} | } | ||||
/** | /** | ||||
* 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 55 Lines • ▼ Show 20 Lines | public function testConfirm(): void | ||||
Queue::fake(); | Queue::fake(); | ||||
$domain_props = ['status' => Domain::STATUS_NEW, 'type' => Domain::TYPE_EXTERNAL]; | $domain_props = ['status' => Domain::STATUS_NEW, 'type' => Domain::TYPE_EXTERNAL]; | ||||
$domain = $this->getTestDomain('ci-failure-none.kolab.org', $domain_props); | $domain = $this->getTestDomain('ci-failure-none.kolab.org', $domain_props); | ||||
$this->assertTrue($domain->confirm() === false); | $this->assertTrue($domain->confirm() === false); | ||||
$this->assertTrue(!$domain->isConfirmed()); | $this->assertFalse($domain->isConfirmed()); | ||||
$domain = $this->getTestDomain('ci-failure-txt.kolab.org', $domain_props); | $domain = $this->getTestDomain('ci-failure-txt.kolab.org', $domain_props); | ||||
$this->assertTrue($domain->confirm() === false); | $this->assertTrue($domain->confirm() === false); | ||||
$this->assertTrue(!$domain->isConfirmed()); | $this->assertFalse($domain->isConfirmed()); | ||||
$domain = $this->getTestDomain('ci-failure-cname.kolab.org', $domain_props); | $domain = $this->getTestDomain('ci-failure-cname.kolab.org', $domain_props); | ||||
$this->assertTrue($domain->confirm() === false); | $this->assertTrue($domain->confirm() === false); | ||||
$this->assertTrue(!$domain->isConfirmed()); | $this->assertFalse($domain->isConfirmed()); | ||||
$domain = $this->getTestDomain('ci-success-txt.kolab.org', $domain_props); | $domain = $this->getTestDomain('ci-success-txt.kolab.org', $domain_props); | ||||
$this->assertTrue($domain->confirm()); | $this->assertTrue($domain->confirm()); | ||||
$this->assertTrue($domain->isConfirmed()); | $this->assertTrue($domain->isConfirmed()); | ||||
$domain = $this->getTestDomain('ci-success-cname.kolab.org', $domain_props); | $domain = $this->getTestDomain('ci-success-cname.kolab.org', $domain_props); | ||||
$this->assertTrue($domain->confirm()); | $this->assertTrue($domain->confirm()); | ||||
$this->assertTrue($domain->isConfirmed()); | $this->assertTrue($domain->isConfirmed()); | ||||
} | } | ||||
} | } |
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.