PHP code example of bogdanghervan / laravel-dummy-observer
1. Go to this page and download the library: Download bogdanghervan/laravel-dummy-observer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bogdanghervan / laravel-dummy-observer example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Flight extends Model
{
protected $fillable = [
'departure',
'destination',
'status'
];
public function landed()
{
$this->status = 'landed';
$this->save();
}
}
namespace Tests\Unit;
use Tests\TestCase;
use App\Models\Flight;
use BogdanGhervan\DummyObserver;
class FlightTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
// Prevent model from being saved
Flight::observe(DummyObserver::class);
}
protected function tearDown(): void
{
DummyObserver::clear();
}
public function testLanded(): void
{
$flight = new Flight([
'departure' => 'Bucharest',
'destination' => 'New York',
]);
$flight->landed();
DummyObserver::assertSavedAttributes([
'departure' => 'Bucharest',
'destination' => 'New York',
'status' => 'landed'
]);
}
}