Passed
Push — master ( 6bc222...ffd20d )
by WEBEWEB
14:18
created

DataTablesWrapperHelperTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
eloc 33
c 2
b 0
f 1
dl 0
loc 88
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetOptions() 0 22 1
A testGetName() 0 10 1
A testGetLanguageUrl() 0 4 1
A testGetLanguageUrlWithFileNotFoundException() 0 9 2
A testHasSearch() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the jquery-datatables-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\JQuery\DataTablesBundle\Tests\Helper;
13
14
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
15
use Throwable;
16
use WBW\Bundle\JQuery\DataTablesBundle\Factory\DataTablesFactory;
17
use WBW\Bundle\JQuery\DataTablesBundle\Helper\DataTablesWrapperHelper;
18
use WBW\Bundle\JQuery\DataTablesBundle\Tests\AbstractTestCase;
19
use WBW\Bundle\JQuery\DataTablesBundle\Tests\Fixtures\TestFixtures;
20
21
/**
22
 * DataTables wrapper helper test.
23
 *
24
 * @author webeweb <https://github.com/webeweb>
25
 * @package WBW\Bundle\JQuery\DataTablesBundle\Tests\Helper
26
 */
27
class DataTablesWrapperHelperTest extends AbstractTestCase {
28
29
    /**
30
     * Tests getLanguageUrl()
31
     *
32
     * @return void
33
     * @throws Throwable Throws an exception if an error occurs.
34
     */
35
    public function testGetLanguageUrl(): void {
36
37
        $res = "/bundles/wbwjquerydatatables/datatables-i18n/French.json";
38
        $this->assertEquals($res, DataTablesWrapperHelper::getLanguageUrl("French"));
39
    }
40
41
    /**
42
     * Tests getLanguageUrl()
43
     *
44
     * @return void
45
     */
46
    public function testGetLanguageUrlWithFileNotFoundException(): void {
47
48
        try {
49
50
            DataTablesWrapperHelper::getLanguageUrl("exception");
51
        } catch (Throwable $ex) {
52
53
            $this->assertInstanceOf(FileNotFoundException::class, $ex);
54
            $this->assertEquals('File "/bundles/wbwjquerydatatables/datatables-i18n/exception.json" could not be found.', $ex->getMessage());
55
        }
56
    }
57
58
    /**
59
     * Tests getName()
60
     *
61
     * @return void
62
     */
63
    public function testGetName(): void {
64
65
        $this->dtProvider->expects($this->any())->method("getName")->willReturn("employee");
0 ignored issues
show
Bug introduced by
The method expects() does not exist on WBW\Bundle\JQuery\DataTa...TablesProviderInterface. ( Ignorable by Annotation )

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

65
        $this->dtProvider->/** @scrutinizer ignore-call */ 
66
                           expects($this->any())->method("getName")->willReturn("employee");

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
        $this->assertEquals("dtemployee", DataTablesWrapperHelper::getName(DataTablesFactory::newWrapper("url", $this->dtProvider)));
67
68
        $this->dtProvider->expects($this->any())->method("getName")->willReturn("employee_");
69
        $this->assertEquals("dtemployee", DataTablesWrapperHelper::getName(DataTablesFactory::newWrapper("url", $this->dtProvider)));
70
71
        $this->dtProvider->expects($this->any())->method("getName")->willReturn("employee-");
72
        $this->assertEquals("dtemployee", DataTablesWrapperHelper::getName(DataTablesFactory::newWrapper("url", $this->dtProvider)));
73
    }
74
75
    /**
76
     * Tests getOptions()
77
     *
78
     * @return void
79
     */
80
    public function testGetOptions(): void {
81
82
        $obj = TestFixtures::getWrapper();
83
84
        $res = [
85
            "ajax"       => [
86
                "type" => "POST",
87
                "url"  => "/datatables/employee/index",
88
            ],
89
            "columns"    => [
90
                ["cellType" => "td", "data" => "name", "name" => "Name"],
91
                ["cellType" => "td", "data" => "position", "name" => "Position"],
92
                ["cellType" => "td", "data" => "office", "name" => "Office"],
93
                ["cellType" => "td", "data" => "age", "name" => "Age"],
94
                ["cellType" => "td", "data" => "startDate", "name" => "Start date"],
95
                ["cellType" => "td", "data" => "salary", "name" => "Salary"],
96
                ["cellType" => "td", "data" => "actions", "name" => "Actions", "orderable" => false, "searchable" => false],
97
            ],
98
            "processing" => true,
99
            "serverSide" => true,
100
        ];
101
        $this->assertEquals($res, DataTablesWrapperHelper::getOptions($obj));
102
    }
103
104
    /**
105
     * Tests hasSearch()
106
     *
107
     * @return void
108
     */
109
    public function testHasSearch(): void {
110
111
        $obj = TestFixtures::getWrapper();
112
        DataTablesFactory::parseWrapper($obj, $this->request);
113
114
        $this->assertFalse(DataTablesWrapperHelper::hasSearch($obj));
115
    }
116
}
117