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 SMW\Tests\SQLStore; |
||
4 | |||
5 | use SMW\DIProperty; |
||
6 | use SMW\DIWikiPage; |
||
7 | use SMW\SemanticData; |
||
8 | use SMW\StoreFactory; |
||
9 | use SMWDITime as DITime; |
||
10 | use SMWSql3StubSemanticData as StubSemanticData; |
||
11 | use Title; |
||
12 | use SMW\Tests\TestEnvironment; |
||
13 | |||
14 | /** |
||
15 | * @covers \SMWSql3StubSemanticData |
||
16 | * |
||
17 | * @group SMW |
||
18 | * @group SMWExtension |
||
19 | * |
||
20 | * @license GNU GPL v2+ |
||
21 | * @since 1.9.0.2 |
||
22 | * |
||
23 | * @author mwjames |
||
24 | */ |
||
25 | class Sql3StubSemanticDataTest extends \PHPUnit_Framework_TestCase { |
||
26 | |||
27 | private $store; |
||
28 | private $testEnvironment; |
||
29 | |||
30 | protected function setUp() { |
||
31 | |||
32 | $this->testEnvironment = new TestEnvironment(); |
||
33 | |||
34 | $this->store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) |
||
35 | ->disableOriginalConstructor() |
||
36 | ->getMock(); |
||
37 | |||
38 | $this->store->expects( $this->any() ) |
||
39 | ->method( 'getRedirectTarget' ) |
||
40 | ->will( $this->returnArgument( 0 ) ); |
||
41 | |||
42 | $this->testEnvironment->registerObject( 'Store', $this->store ); |
||
43 | } |
||
44 | |||
45 | protected function tearDown() { |
||
46 | $this->testEnvironment->tearDown(); |
||
47 | } |
||
48 | |||
49 | public function testCanConstruct() { |
||
50 | |||
51 | $subject = DIWikiPage::newFromTitle( Title::newFromText( __METHOD__ ) ); |
||
52 | |||
53 | $semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
||
54 | ->disableOriginalConstructor() |
||
55 | ->getMock(); |
||
56 | |||
57 | $semanticData->expects( $this->once() ) |
||
58 | ->method( 'getSubject' ) |
||
59 | ->will( $this->returnValue( $subject ) ); |
||
60 | |||
61 | $this->assertInstanceOf( |
||
62 | '\SMWSql3StubSemanticData', |
||
63 | StubSemanticData::newFromSemanticData( $semanticData, $this->store ) |
||
64 | ); |
||
65 | } |
||
66 | |||
67 | public function testNotToResolveSubobjectsForRedirect() { |
||
68 | |||
69 | $instance = $this->getMockBuilder( '\SMWSql3StubSemanticData' ) |
||
70 | ->disableOriginalConstructor() |
||
71 | ->setMethods( array( |
||
72 | 'getProperties', |
||
73 | 'isRedirect', |
||
74 | 'getPropertyValues' ) ) |
||
75 | ->getMock(); |
||
76 | |||
77 | $instance->expects( $this->once() ) |
||
78 | ->method( 'getProperties' ) |
||
79 | ->will( $this->returnValue( array( new DIProperty( '_SOBJ' ) ) ) ); |
||
80 | |||
81 | $instance->expects( $this->once() ) |
||
82 | ->method( 'isRedirect' ) |
||
83 | ->will( $this->returnValue( true ) ); |
||
84 | |||
85 | $instance->expects( $this->never() ) |
||
86 | ->method( 'getPropertyValues' ); |
||
87 | |||
88 | $instance->getSubSemanticData(); |
||
89 | } |
||
90 | |||
91 | public function testGetPropertyValues() { |
||
92 | |||
93 | $instance = StubSemanticData::newFromSemanticData( |
||
94 | new SemanticData( DIWikiPage::newFromTitle( Title::newFromText( __METHOD__ ) ) ), |
||
95 | $this->store |
||
96 | ); |
||
97 | |||
98 | $this->assertInstanceOf( |
||
99 | 'SMW\DIWikiPage', |
||
100 | $instance->getSubject() |
||
101 | ); |
||
102 | |||
103 | $this->assertEmpty( |
||
104 | $instance->getPropertyValues( new DIProperty( 'unknownInverseProperty', true ) ) |
||
105 | ); |
||
106 | |||
107 | $this->assertEmpty( |
||
108 | $instance->getPropertyValues( new DIProperty( 'unknownProperty' ) ) |
||
109 | ); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @dataProvider propertyObjectProvider |
||
114 | */ |
||
115 | public function testPhpSerialization( $property, $dataItem ) { |
||
116 | |||
117 | $instance = StubSemanticData::newFromSemanticData( |
||
118 | new SemanticData( new DIWikiPage( 'Foo', NS_MAIN ) ), |
||
0 ignored issues
–
show
|
|||
119 | $this->store |
||
120 | ); |
||
121 | |||
122 | $instance->addPropertyObjectValue( |
||
123 | $property, |
||
124 | $dataItem |
||
125 | ); |
||
126 | |||
127 | $serialization = serialize( $instance ); |
||
128 | |||
129 | $this->assertEquals( |
||
130 | $instance->getHash(), |
||
131 | unserialize( $serialization )->getHash() |
||
132 | ); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @dataProvider propertyObjectProvider |
||
137 | */ |
||
138 | public function testRemovePropertyObjectValue( $property, $dataItem ) { |
||
139 | |||
140 | $instance = StubSemanticData::newFromSemanticData( |
||
141 | new SemanticData( new DIWikiPage( 'Foo', NS_MAIN ) ), |
||
0 ignored issues
–
show
new \SMW\SemanticData(ne...kiPage('Foo', NS_MAIN)) of type object<SMW\SemanticData> is not a sub-type of object<SMWSemanticData> . It seems like you assume a child class of the class SMW\SemanticData to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.
Loading history...
|
|||
142 | $this->store |
||
143 | ); |
||
144 | |||
145 | $instance->addPropertyObjectValue( $property, $dataItem ); |
||
146 | $this->assertFalse( $instance->isEmpty() ); |
||
147 | |||
148 | $instance->removePropertyObjectValue( $property, $dataItem ); |
||
149 | $this->assertTrue( $instance->isEmpty() ); |
||
150 | } |
||
151 | |||
152 | public function propertyObjectProvider() { |
||
153 | |||
154 | $provider = array(); |
||
155 | |||
156 | // #0 |
||
157 | $provider[] = array( |
||
158 | new DIProperty( '_MDAT' ), |
||
159 | DITime::newFromTimestamp( 1272508903 ) |
||
160 | ); |
||
161 | |||
162 | return $provider; |
||
163 | } |
||
164 | |||
165 | } |
||
166 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.