Passed
Push — main ( fd5484...10601e )
by Thierry
05:13
created

NamespaceTest::testPluginName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Jaxon\Tests\TestRegistration;
4
5
use Jaxon\App\Component\Pagination;
6
use Jaxon\Exception\SetupException;
7
use Jaxon\Jaxon;
8
use Jaxon\Plugin\Request\CallableClass\CallableClassPlugin;
9
use Jaxon\Plugin\Request\CallableClass\CallableObject;
10
use Jaxon\Plugin\Request\CallableClass\CallableDirPlugin;
11
use Jaxon\Tests\Ns\Ajax\ClassA;
12
use Jaxon\Tests\Ns\Ajax\ClassB;
13
use Jaxon\Tests\Ns\Ajax\ClassC;
14
use PHPUnit\Framework\TestCase;
15
16
use function strlen;
17
18
class NamespaceTest extends TestCase
19
{
20
    /**
21
     * @var CallableDirPlugin
22
     */
23
    protected $xDirPlugin;
24
25
    /**
26
     * @var CallableClassPlugin
27
     */
28
    protected $xClassPlugin;
29
30
    /**
31
     * @throws SetupException
32
     */
33
    public function setUp(): void
34
    {
35
        jaxon()->setOption('core.prefix.class', '');
36
37
        // This directory is already registered with the autoload.
38
        jaxon()->register(Jaxon::CALLABLE_DIR, __DIR__ . '/../src/Ns/Ajax',
39
            ['namespace' => "Jaxon\\Tests\\Ns\\Ajax", 'autoload' => false]);
40
        // This directory needs to be registered with the autoload.
41
        jaxon()->register(Jaxon::CALLABLE_DIR, __DIR__ . '/../src/dir_ns', "Jaxon\\NsTests");
42
43
        $this->xDirPlugin = jaxon()->di()->getCallableDirPlugin();
44
        $this->xClassPlugin = jaxon()->di()->getCallableClassPlugin();
45
    }
46
47
    /**
48
     * @throws SetupException
49
     */
50
    public function tearDown(): void
51
    {
52
        jaxon()->reset();
53
        parent::tearDown();
54
    }
55
56
    /**
57
     * @throws SetupException
58
     */
59
    public function testRegisterWithUnderscoreAsSeparator()
60
    {
61
        jaxon()->register(Jaxon::CALLABLE_CLASS, ClassA::class);
62
        jaxon()->register(Jaxon::CALLABLE_CLASS, ClassB::class);
63
        jaxon()->register(Jaxon::CALLABLE_CLASS, ClassC::class);
64
        // The js is generated by the CallableClass plugin
65
        // $this->assertEquals('a345cf8862e7ce14752fba0e789adc1c', $this->xClassPlugin->getHash());
66
        $this->assertEquals(32, strlen($this->xClassPlugin->getHash()));
67
        $sJsCode = $this->xClassPlugin->getScript();
68
        // file_put_contents(__DIR__ . '/../src/js/nsu.js', $sJsCode);
69
        $this->assertEquals(file_get_contents(__DIR__ . '/../src/js/nsu.js'), $sJsCode);
70
71
        $xCallable = $this->xClassPlugin->getCallable('Jaxon_Tests_Ns_Ajax_ClassA');
72
        $this->assertEquals(CallableObject::class, get_class($xCallable));
0 ignored issues
show
Bug introduced by
It seems like $xCallable can also be of type null; however, parameter $object of get_class() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

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

72
        $this->assertEquals(CallableObject::class, get_class(/** @scrutinizer ignore-type */ $xCallable));
Loading history...
73
    }
74
}
75