Completed
Push — master ( 67e2ab...0cf4c0 )
by Freek
01:31
created

it_logs_the_method_call_when_log_is_set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spatie\Newsletter\Test;
4
5
use Spatie\Newsletter\NullDriver;
6
use Illuminate\Support\Facades\Log;
7
8
class NullDriverTest extends \PHPUnit\Framework\TestCase
9
{
10
    protected function tearDown(): void
11
    {
12
        parent::tearDown();
13
        \Mockery::close();
14
    }
15
16
    /** @test */
17
    public function it_can_be_call_with_any_method()
18
    {
19
        $subject = new NullDriver();
20
21
        $this->assertNull($subject->whatever());
0 ignored issues
show
Documentation Bug introduced by
The method whatever does not exist on object<Spatie\Newsletter\NullDriver>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
22
        $this->assertNull($subject->subscription());
0 ignored issues
show
Documentation Bug introduced by
The method subscription does not exist on object<Spatie\Newsletter\NullDriver>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
23
        $this->assertNull($subject->addTags('[email protected]', ['tags']));
0 ignored issues
show
Documentation Bug introduced by
The method addTags does not exist on object<Spatie\Newsletter\NullDriver>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
24
    }
25
26
    /** @test */
27
    public function it_logs_the_method_call_when_log_is_set()
28
    {
29
        $subject = new NullDriver(true);
30
31
        $log = \Mockery::mock();
32
        Log::swap($log);
33
34
        $log->shouldReceive('debug')->twice();
35
36
        $this->assertNull($subject->whatever());
0 ignored issues
show
Documentation Bug introduced by
The method whatever does not exist on object<Spatie\Newsletter\NullDriver>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
37
        $this->assertNull($subject->addTags('[email protected]', ['tags']));
0 ignored issues
show
Documentation Bug introduced by
The method addTags does not exist on object<Spatie\Newsletter\NullDriver>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
38
39
        $log->shouldHaveReceived('debug', ['Called Spatie Newsletter facade method: whatever with:', []]);
40
        $log->shouldHaveReceived('debug', ['Called Spatie Newsletter facade method: addTags with:', ['[email protected]', ['tags']]]);
41
    }
42
}
43