Skip to content

Instantly share code, notes, and snippets.

@gizzmo
Created June 6, 2017 03:42
Show Gist options
  • Save gizzmo/e17d3489e011589ca4cbbaa432571020 to your computer and use it in GitHub Desktop.
Save gizzmo/e17d3489e011589ca4cbbaa432571020 to your computer and use it in GitHub Desktop.
First time doing PHPUnit testing. And I think I might not be doing this right.
<?php
namespace Tests\Unit;
use Mockery;
use Carbon\Carbon;
use Tests\TestCase;
use App\ScheduleProcessor;
use App\Contracts\MailMessage;
use Illuminate\Support\Collection;
class ScheduleProcessorTest extends TestCase
{
public function testFindsEvents()
{
$message = Mockery::mock(MailMessage::class);
$message->shouldReceive('getBody')->once()
->andReturn(file_get_contents($this->app->basePath('tests/emails/HasLunchBreaks.txt')));
$events = (new ScheduleProcessor($message))->events();
$this->assertInstanceOf(Collection::class, $events);
$this->assertEquals(6, $events->count());
//
$event = $events->first();
$this->assertInternalType('array', $event);
$this->assertInternalType('string', $event['title']);
$this->assertInstanceOf(Carbon::class, $event['start']);
$this->assertInstanceOf(Carbon::class, $event['finish']);
$this->assertEquals('7.5 - Carts', $event['title']);
$this->assertEquals('2017-06-04 08:00:00', $event['start']->toDateTimeString());
$this->assertEquals('2017-06-04 16:00:00', $event['finish']->toDateTimeString());
$event = $events->last();
$this->assertInternalType('string', $event['title']);
$this->assertInstanceOf(Carbon::class, $event['date']);
$this->assertEquals('30.5 Weekly Hours', $event['title']);
$this->assertEquals('2017-06-10', $event['date']->toDateString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment