/**
* @test
*/
public function can_spool_and_schedule()
{
$tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . microtime(true);
$spoolDir = $tmpDir . DIRECTORY_SEPARATOR . 'spool';
if (@mkdir($tmpDir, 0755, true) === false) {
$this->fail('Could not create temporary directory');
}
if (@mkdir($spoolDir . DIRECTORY_SEPARATOR . 'outgoing', 0755, true) === false) {
$this->fail('Could not create temporary spool directory');
}
$props = array('tmpDir' => $tmpDir, 'spoolDir' => $spoolDir);
$spool = \PAGI\CallSpool\Impl\CallSpoolImpl::getInstance($props);
$call = new \PAGI\CallSpool\CallFile(new \PAGI\DialDescriptor\SIPDialDescriptor('target', 'provider'));
$call->unserialize(<<<TEXT
Channel: SIP/target@provider
Archive: Yes
Context: context
Priority: priority
Extension: extension
Application: application
AlwaysDelete: Yes
CallerID: callerId
MaxRetries: 33
RetryTime: 44
WaitTime: 22
Account: account
Data: a,b,c
aaaa:
Set: var=value
Set: var2=
TEXT
);
$file = $spool->spool($call, 12);
$content = <<<TEXT
Channel: SIP/target@provider
Archive: Yes
Context: context
Priority: priority
Extension: extension
Application: application
AlwaysDelete: Yes
CallerID: callerId
MaxRetries: 33
RetryTime: 44
WaitTime: 22
Account: account
Data: a,b,c
aaaa: ?
Set: var=value
Set: var2=?
TEXT;
$this->assertEquals(file_get_contents($file), $content);
$this->assertEquals(filemtime($file), 12);
if (@unlink($file) === false) {
$this->fail('could not remove call file: ' . $file);
}
if (@rmdir($spoolDir . DIRECTORY_SEPARATOR . 'outgoing') === false) {
$this->fail('could not remove temporary spool outgoing directory');
}
if (@rmdir($spoolDir) === false) {
$this->fail('could not remove temporary spool directory');
}
if (@rmdir($tmpDir) === false) {
$this->fail('could not remove temporary directory');
}
}