Completed
Push — master ( d57f7c...e95de4 )
by Iman
02:08
created

WidgetTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 70.69 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 41
loc 58
rs 10
wmc 5
lcom 0
cbo 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_presenter_method_is_called_with_data_from_controller() 0 10 1
A test_default_view_name_is_figured_out_correctly() 11 11 1
A test_context_as_is_passes_to_view_correctly() 11 11 1
A test_controller_method_is_called_on_some_other_class() 10 10 1
A test_data_is_passed_to_data_method_from_view() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 5 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
require_once 'test_stubs.php';
4
5
class WidgetTest extends TestCase
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    public function test_presenter_method_is_called_with_data_from_controller()
8
    {
9
        View::shouldReceive('exists')->once()->andReturn(true);
10
        View::shouldReceive('make')->once()->with('hello', ['data' => 'barfoo'], [])->andReturn(app('view'));
11
        View::shouldReceive('render')->once()->andReturn('<br>');
12
13
        //act
14
        $widget = new Widget5();
15
        render_widget($widget);
16
    }
17
18 View Code Duplication
    public function test_default_view_name_is_figured_out_correctly()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    {
20
        View::shouldReceive('exists')->once()->andReturn(true);
21
        View::shouldReceive('make')->once()->with('Widgets::Foo.Widget1View', ['data' => 'foo'], [])->andReturn(app('view'));
22
        View::shouldReceive('render')->once()->andReturn('<br>');
23
        \App::shouldReceive('call')->once()->andReturn('foo');
24
25
        //act
26
        $widget = new \App\Widgets\Foo\Widget1();
27
        render_widget($widget);
28
    }
29
30 View Code Duplication
    public function test_context_as_is_passes_to_view_correctly()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        View::shouldReceive('exists')->once()->andReturn(true);
33
        View::shouldReceive('make')->once()->with('hello', ['myData' => 'foo'], [])->andReturn(app('view'));
34
        View::shouldReceive('render')->once()->andReturn('<br>');
35
        \App::shouldReceive('call')->once()->andReturn('foo');
36
37
        //act
38
        $widget = new Widget3();
39
        render_widget($widget);
40
    }
41
42 View Code Duplication
    public function test_controller_method_is_called_on_some_other_class()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    {
44
        View::shouldReceive('exists')->once()->andReturn(true);
45
        View::shouldReceive('make')->once()->with('hello', ['data' => 'aaabbb'], [])->andReturn(app('view'));
46
        View::shouldReceive('render')->once()->andReturn('<br>');
47
48
        //act
49
        $widget = new Widget4();
50
        render_widget($widget, ['arg1' => 'aaa', 'arg2' => 'bbb']);
51
    }
52
53 View Code Duplication
    public function test_data_is_passed_to_data_method_from_view()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        View::shouldReceive('exists')->once()->andReturn(true);
56
        View::shouldReceive('make')->once()->with('hello', ['data' => '222111'], [])->andReturn(app('view'));
57
        View::shouldReceive('render')->once()->andReturn('<br>');
58
        //act
59
        $widget = new Widget6();
60
        render_widget($widget, ['foo' => '111', 'bar' => '222']);
61
    }
62
}
63