/** * Setup the test environment. * * @return void */ public function setUp() { parent::setUp(); // Create an artisan object for calling migrations $artisan = $this->app->make('artisan'); // Call migrations specific to our tests, e.g. to seed the db $artisan->call('migrate', ['--database' => 'testbench', '--path' => '../tests/Migrations']); Models\ModelWithTraitAndBootObserver::observe(new \Sleavely\Datadiff\DatadiffObserver()); }
/** * Test alternate syntax for getting commits * from the end of the commits array. */ public function testGetVersionFromEndOfArray() { $model = new Models\ModelWithTraitAndBootObserver(); $model->fill(['author_id' => 1337, 'title' => 'Version 1', 'body' => 'Content goes here.', 'published' => true, 'id' => 8]); $model->save(); $model->title = 'Version 2'; $model->save(); $model->title = 'Version 3'; $model->save(); $model->title = 'Version 4'; $model->save(); // Get most recent version $diff = $model->diff(-1); $this->assertEquals('Version 3', $diff['data']['title']); // Second most recent version $diff = $model->diff(-2); $this->assertEquals('Version 2', $diff['data']['title']); // And going too far back gives us nothing $diff = $model->diff(-10); $this->assertNull($diff); }