Skip to content

Instantly share code, notes, and snippets.

@marceloandrader
Last active August 22, 2017 14:42
Show Gist options
  • Save marceloandrader/86304dd2933ed59deaba692dffa4f448 to your computer and use it in GitHub Desktop.
Save marceloandrader/86304dd2933ed59deaba692dffa4f448 to your computer and use it in GitHub Desktop.
Pruebas Unitarias
<?php namespace Test\Handler;
use mef\DB\Mock\Driver;
use mef\DB\Mock\SequentialArrayDataProvider;
use mef\Db\Driver\DataProvider\SequentialArrayDataProvider as OldSequentialArrayDataProvider;
use mef\Db\Driver\DataProviderDriver as OldDriver;
use Fibroblast\Handler\AcceptTermsHandler;
use Fibroblast\Command\AcceptTermsCommand;
/**
* AcceptTermsHandlerTest documentation @TODO...
*/
class AcceptTermsHandlerTest extends \Test\UnitTestCase
{
private function getHandler($data)
{
$providerOld = new SequentialArrayDataProvider($data);
$mockDbOld = new Driver($providerOld);
$provider = new OldSequentialArrayDataProvider($data);
$mockDb = new OldDriver($provider);
$orm = include __DIR__.'/../../Orm.php';
$orm->db = $mockDbOld;
return new AcceptTermsHandler($mockDb, $orm);
}
/**
* @expectedException \Fibroblast\Exception\UnexpectedCommandException
*/
public function testInvalidCommand()
{
$this->getHandler([])->handleCommand($this->getMock('Fibroblast\Command\CommandInterface'));
}
public function testCommand()
{
$user = new \Fibroblast\CurrentUser();
$command = new AcceptTermsCommand($this->getUser($this->getORM()));
$result = $this->getHandler([
0 => [['id' => 1, 'username' => 'username', 'terms_accepted_dt' => null]],
])->handleCommand($command);
$this->assertNotNull($result);
}
}
<?php
namespace Test\Handler;
use mef\DB\Mock\Driver;
use mef\DB\Mock\SequentialArrayDataProvider;
use mef\Db\Driver\DataProvider\SequentialArrayDataProvider as OldSequentialArrayDataProvider;
use mef\Db\Driver\DataProviderDriver as OldDriver;
use Fibroblast\Handler\CreateAccountHandler;
use Fibroblast\Command\CreateAccountCommand;
/**
* CreateAccountHandlerTest documentation @TODO...
*/
class CreateAccountHandlerTest extends \Test\UnitTestCase
{
private function getHandler($data)
{
$providerOld = new SequentialArrayDataProvider($data);
$mockDbOld = new Driver($providerOld);
$provider = new OldSequentialArrayDataProvider($data);
$mockDb = new OldDriver($provider);
$orm = include __DIR__.'/../../Orm.php';
$orm->db = $mockDbOld;
$password = new \Fibroblast\Service\Password();
$mockedBus = new \Fibroblast\Bus\MockBus(function () {});
return new CreateAccountHandler($mockDb, $orm, $password, $mockedBus);
}
/**
* @expectedException \Fibroblast\Exception\UnexpectedCommandException
*/
public function testInvalidCommand()
{
$this->getHandler([])->handleCommand($this->getMock('Fibroblast\Command\CommandInterface'));
}
public function testCommand()
{
$acc = new \Fibroblast\Object\CreateAccount();
$command = new CreateAccountCommand(
$this->getUser(),
$acc);
$result = $this->getHandler([
0 => [],
])->handleCommand($command);
$this->assertNotNull($result);
}
/**
* @expectedException \Fibroblast\Exception\DuplicateAccountException
*/
public function testCommandDuplicate()
{
$acc = new \Fibroblast\Object\CreateAccount();
$command = new CreateAccountCommand(
$this->getUser(),
$acc);
$result = $this->getHandler([
0 => [['id' => 1]],
])->handleCommand($command);
$this->assertNotNull($result);
}
}
<?php
class ImportEmailNotesTest extends \Codeception\Test\Unit
{
/**
* @var \UnitTester
*/
protected $tester;
protected $notesImport;
protected function _before()
{
$this->notesImport = new \PhalconRest\Libraries\Email\Notes();
}
protected function _after()
{
}
// tests
public function testFindMatter()
{
$mailToImport = new \PhpImap\IncomingMail;
$mailToImport->fromAddress = '[email protected]'; // It has to be an employee
$mailToImport->textPlain = "Hello this is a note about case [JR18601]";
$m = $this->notesImport->findMatter($mailToImport->textPlain);
$this->assertEquals(403, $m->id);
}
public function testFindNoMatter()
{
$mailToImport = new \PhpImap\IncomingMail;
$mailToImport->fromAddress = '[email protected]'; // It has to be an employee
$mailToImport->textPlain = "Hello this is a note about case JR18601]";
$m = $this->notesImport->findMatter($mailToImport->textPlain);
$this->assertNull($m);
}
public function testImportEmail()
{
$mailToImport = new \PhpImap\IncomingMail;
$mailToImport->fromAddress = '[email protected]'; // It has to be an employee
$mailToImport->textPlain = "Hello this is a note about case [JR18601]";
$noteId = $this->notesImport->importEmail($mailToImport);
$this->assertNotNull($noteId);
}
public function testImportNotFoundEmail()
{
$mailToImport = new \PhpImap\IncomingMail;
$mailToImport->fromAddress = '[email protected]'; // It is not an employee
$mailToImport->textPlain = "Hello this is a note about case [JR18601]";
$noteId = $this->notesImport->importEmail($mailToImport);
$this->assertFalse($noteId);
}
}
<?php
namespace Test\Object;
class TwilioClientTest extends \Test\UnitTestCase
{
public function testPass()
{
$this->assertTrue(true);
}
// Uncomment the x to run this test
public function xtestSendSMS()
{
$client = new \Fibroblast\Service\TwilioClient(
[
'account_id' => 'AC5c519573a3fcb332eb877fc1e1eba43e',
'auth_token' => '2ed9d6ec0b6a1209cebca6ea51753811',
'from_number' => '+15005550006',
]);
$id = $client->sendSMS('+593999443360', 'hi');
$this->assertNotNull($id);
}
public function testSplitMessage()
{
$client = new \Fibroblast\Service\TwilioClient(
[
'account_id' => 'AC5c519573a3fcb332eb877fc1e1eba43e',
'auth_token' => '2ed9d6ec0b6a1209cebca6ea51753811',
'from_number' => '+15005550006',
]);
$msg = '123';
$result = $client->splitMessage($msg);
$this->assertEquals('123', $result);
$msg = str_repeat('123456789 ', 16);
$result = $client->splitMessage($msg);
$this->assertEquals($msg, $result);
$msg = '123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789';
$result = $client->splitMessage($msg);
$this->assertEquals('(1/2) 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 (2/2) 123456789 123456789', $result);
$message = 'It looks like you didn’t show up for your scheduled appointment with Dr. Andrade.';
$message = $message.' You can reschedule your appointment by calling Dr. Andrade’s office at (123) 456-7890';
$message = $message.' Please contact the doctor that referred you, Dr. Jacob, with questions - (987) 567-0981.';
$message = $message.' Otherwise please contact Fibroblast for referring to another doctor';
$result = $client->splitMessage($message);
$this->assertEquals('(1/3) It looks like you didn’t show up for your scheduled appointment with Dr. Andrade. You can reschedule your appointment by calling Dr. Andrade’s office '.
'(2/3) at (123) 456-7890 Please contact the doctor that referred you, Dr. Jacob, with questions - (987) 567-0981. Otherwise please contact Fibroblast for '.
'(3/3) referring to another doctor', $result);
$msg = str_repeat('123456789 ', 80);
$result = $client->splitMessage($msg);
$this->assertEquals('(1/6) 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 '.
'(2/6) 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 '.
'(3/6) 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 '.
'(4/6) 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 '.
'(5/6) 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 '.
'(6/6) 123456789 123456789 123456789 123456789 123456789', $result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment