Repository URL to install this package:
|
Version:
2.2.0 ▾
|
<?php
namespace CrazyFactory\Jobs\Tests;
use CrazyFactory\Jobs\JobConfig;
use CrazyFactory\Jobs\JobManager;
class JobManagerTest extends \PHPUnit_Framework_TestCase
{
public function testWithJob() {
$jobManager = new JobManager();
$this->assertFalse($jobManager->has('foo'));
$jobManager->withJob(new JobConfig(['name' => 'foo']));
$this->assertTrue($jobManager->has('foo'));
}
public function testWithJobs() {
$jobManager = new JobManager();
$this->assertEquals(0, count($jobManager->getAll()));
// should still be 0 after default key
$jobManager->withJobs(['default' => ['foo' => 'bar']]);
$this->assertEquals(0, count($jobManager->getAll()));
$this->assertEquals(['foo' => 'bar'], $jobManager->getDefault()->toArray());
$jobManager->withJobs(['defaultAlt' => ['apple' => 'pie']], 'defaultAlt');
$this->assertEquals(0, count($jobManager->getAll()));
$this->assertEquals(['apple' => 'pie'], $jobManager->getDefault()->toArray());
// add jobs
$jobManager->withJobs([
[
'name' => 'alice',
'test' => true
],
'bob' => [
'enabled' => true
],
'charly' => [
'name' => 'charlotte',
'singleton' => true
],
new JobConfig(['name' => 'dave']),
'emma' => new JobConfig(['name' => 'esmeralda'])
]);
$this->assertTrue($jobManager->has('alice'));
$this->assertTrue($jobManager->has('bob'));
$this->assertTrue($jobManager->has('charlotte'));
$this->assertTrue($jobManager->has('dave'));
$this->assertTrue($jobManager->has('esmeralda'));
// converted to real jobs
$this->assertInstanceOf(JobConfig::class, $jobManager->get('charlotte'));
}
public function testGetAll() {
$jobManager = new JobManager();
$this->assertEquals(0, count($jobManager->getAll()));
$jobManager->withJobs([
['name' => 'alice'],
['name' => 'bob']
]);
$this->assertEquals(['alice', 'bob'], array_keys($jobManager->getAll()));
}
public function toArray() {
$jobManager = new JobManager();
$this->assertEquals(['default' => null, 'jobs' => []], $jobManager->toArray());
$jobManager->withJobs([
'default' => ['apple' => 'pie'],
'alice' => ['a' => true],
'bob' => ['b' => false]
]);
$expected = [
'default' => ['apple' => 'pie'],
'jobs' => [
'alice' => [
'name' => 'alice',
'a' => true
],
'bob' => [
'name' => 'bob',
'b' => false
]
]
];
$this->assertEquals($expected, $jobManager->toArray());
}
}