HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/ai.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();

    }
}