File: /home/xedaptot/be.naniguide.com/tests/Unit/SubscriberMockTest.php
<?php
namespace Tests\Unit;
use App\Model\Subscriber;
use Illuminate\Support\Collection;
use Mockery;
use Tests\TestCase;
class SubscriberMockTest extends TestCase
{
protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}
/** @test */
public function test_it_creates_a_clean_fake_subscriber()
{
$fake = Subscriber::fake(
attributes: [
'email' => '[email protected]',
'first_name' => 'Testy',
],
methods: [
'getFullName' => 'Testy McMock',
],
relations: [
'list' => ['name' => 'Demo List'],
]
);
// ✅ correct type
$this->assertInstanceOf(Subscriber::class, $fake);
// ✅ attributes
$this->assertEquals('[email protected]', $fake->email);
$this->assertEquals('Testy', $fake->first_name);
// ✅ mocked method
$this->assertEquals('Testy McMock', $fake->getFullName());
// ✅ mocked relation
$this->assertEquals('Demo List', $fake->list['name']);
// ✅ strict mode: undefined method should throw
$this->expectException(\BadMethodCallException::class);
$fake->undefinedMethod();
}
/** @test */
public function test_it_throws_on_unknown_methods()
{
$fake = Subscriber::fake([], [], []);
// Should throw
$this->expectException(\LogicException::class);
$fake->someUndefinedMethod();
}
}