These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace SWL\Tests; |
||
4 | |||
5 | use SWL\TableUpdater; |
||
6 | |||
7 | /** |
||
8 | * @covers \SWL\TableUpdater |
||
9 | * |
||
10 | * @group semantic-watchlist |
||
11 | * |
||
12 | * @license GNU GPL v2+ |
||
13 | * @since 1.0 |
||
14 | * |
||
15 | * @author mwjames |
||
16 | */ |
||
17 | class TableUpdaterTest extends \PHPUnit_Framework_TestCase { |
||
18 | |||
19 | public function testCanConstruct() { |
||
20 | |||
21 | $connectionProvider = $this->getMockBuilder( '\SWL\LazyDBConnectionProvider' ) |
||
22 | ->disableOriginalConstructor() |
||
23 | ->getMock(); |
||
24 | |||
25 | $this->assertInstanceOf( |
||
26 | '\SWL\TableUpdater', |
||
27 | new TableUpdater( $connectionProvider ) |
||
28 | ); |
||
29 | } |
||
30 | |||
31 | public function testUpdateGroupIdsForUserToReplaceDatasetByUserId() { |
||
32 | |||
33 | $userId = 1111; |
||
34 | $groupIds = array( 1, 9999 ); |
||
35 | |||
36 | $transactionProfiler = $this->getMockBuilder( '\Wikimedia\Rdbms\TransactionProfiler' ) |
||
0 ignored issues
–
show
|
|||
37 | ->disableOriginalConstructor() |
||
38 | ->getMock(); |
||
39 | |||
40 | $connection = $this->getMockBuilder( 'DatabaseBase' ) |
||
41 | ->disableOriginalConstructor() |
||
42 | ->setMethods( array( 'isOpen', 'delete', 'insert' ) ) |
||
43 | ->getMockForAbstractClass(); |
||
44 | |||
45 | $connection->expects( $this->once() ) |
||
46 | ->method( 'delete' ) |
||
47 | ->with( |
||
48 | $this->equalTo( 'swl_users_per_group' ), |
||
49 | $this->equalTo( array( 'upg_user_id' => $userId ) ) ); |
||
50 | |||
51 | $connection->expects( $this->any() ) |
||
52 | ->method( 'isOpen' ) |
||
53 | ->will( $this->returnValue( true ) ); |
||
54 | |||
55 | $connection->expects( $this->at( 2 ) ) |
||
56 | ->method( 'insert' ) |
||
57 | ->will( $this->returnValue( true ) ); |
||
58 | |||
59 | $connectionProvider = $this->getMockBuilder( '\SWL\LazyDBConnectionProvider' ) |
||
60 | ->disableOriginalConstructor() |
||
61 | ->getMock(); |
||
62 | |||
63 | $connectionProvider->expects( $this->any() ) |
||
64 | ->method( 'getConnection' ) |
||
65 | ->will( $this->returnValue( $connection ) ); |
||
66 | |||
67 | $instance = new TableUpdater( $connectionProvider ); |
||
68 | |||
69 | $this->assertTrue( |
||
70 | $instance->updateGroupIdsForUser( $userId, $groupIds ) |
||
71 | ); |
||
72 | } |
||
73 | |||
74 | public function testUpdateGroupIdsForUserToOnlyDeleteDatasetByUserId() { |
||
75 | |||
76 | $userId = 1111; |
||
77 | $groupIds = array(); |
||
78 | |||
79 | $connection = $this->getMockBuilder( 'DatabaseBase' ) |
||
80 | ->disableOriginalConstructor() |
||
81 | ->setMethods( array( 'isOpen', 'delete', 'insert' ) ) |
||
82 | ->getMockForAbstractClass(); |
||
83 | |||
84 | $connection->expects( $this->once() ) |
||
85 | ->method( 'delete' ) |
||
86 | ->with( |
||
87 | $this->equalTo( 'swl_users_per_group' ), |
||
88 | $this->equalTo( array( 'upg_user_id' => $userId ) ) ); |
||
89 | |||
90 | $connection->expects( $this->any() ) |
||
91 | ->method( 'isOpen' ) |
||
92 | ->will( $this->returnValue( true ) ); |
||
93 | |||
94 | $connection->expects( $this->never() ) |
||
95 | ->method( 'insert' ) |
||
96 | ->will( $this->returnValue( true ) ); |
||
97 | |||
98 | $connectionProvider = $this->getMockBuilder( '\SWL\LazyDBConnectionProvider' ) |
||
99 | ->disableOriginalConstructor() |
||
100 | ->getMock(); |
||
101 | |||
102 | $connectionProvider->expects( $this->any() ) |
||
103 | ->method( 'getConnection' ) |
||
104 | ->will( $this->returnValue( $connection ) ); |
||
105 | |||
106 | $instance = new TableUpdater( $connectionProvider ); |
||
107 | |||
108 | $this->assertTrue( |
||
109 | $instance->updateGroupIdsForUser( $userId, $groupIds ) |
||
110 | ); |
||
111 | } |
||
112 | |||
113 | } |
||
114 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.