Test Setup Failed
Branch master (17e5cc)
by Gaetano
02:18
created

testPrototypeCanBeCalled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace skrtdev\PrototypesTests;
4
5
use Error;
6
use skrtdev\Prototypes\Exception;
7
use PHPUnit\Framework\TestCase;
8
use skrtdev\Prototypes\Prototypes;
9
10
class PrototypesIsPrototypeableTest extends TestCase
11
{
12
13
    public function testPrototypeCanBeCreated(): void
14
    {
15
        $this->assertNull(Prototypes::addStaticMethod('prototypeStaticMethod', fn() => true));
0 ignored issues
show
Bug introduced by
Are you sure the usage of skrtdev\Prototypes\Proto...ion(...) { /* ... */ }) targeting skrtdev\Prototypes\Prototypes::addStaticMethod() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
16
    }
17
18
    public function testPrototypeCanBeCalled(): void
19
    {
20
        $this->assertTrue(Prototypes::prototypeStaticMethod());
0 ignored issues
show
Bug introduced by
The method prototypeStaticMethod() does not exist on skrtdev\Prototypes\Prototypes. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        $this->assertTrue(Prototypes::/** @scrutinizer ignore-call */ prototypeStaticMethod());
Loading history...
21
    }
22
23
    public function testErrorIsThrownInNonExistentMethods(): void
24
    {
25
        $this->expectException(Error::class);
26
        Prototypes::nonExistentStaticMethod();
0 ignored issues
show
Bug introduced by
The method nonExistentStaticMethod() does not exist on skrtdev\Prototypes\Prototypes. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        Prototypes::/** @scrutinizer ignore-call */ 
27
                    nonExistentStaticMethod();
Loading history...
27
    }
28
29
    public function testCantOverridePrototypes(): void
30
    {
31
        $this->expectException(Exception::class);
32
        Prototypes::addStaticMethod('prototypeStaticMethod', fn() => true);
33
    }
34
35
    public function testCantOverrideMethods(): void
36
    {
37
        $this->expectException(Exception::class);
38
        // isPrototypeable is an existent static method
39
        Prototypes::addStaticMethod('isPrototypeable', fn() => true);
40
    }
41
42
    public function testCantAddNonStaticMethods(): void
43
    {
44
        $this->expectException(Exception::class);
45
        // Prototypes class is not intended to have non-static methods
46
        Prototypes::addMethod('justARandomMethod', fn() => true);
47
    }
48
49
}
50