This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
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 Tests\Wikibase\DataModel\Serializers; |
||
| 4 | |||
| 5 | use Serializers\Serializer; |
||
| 6 | use Wikibase\DataModel\Entity\Item; |
||
| 7 | use Wikibase\DataModel\Entity\Property; |
||
| 8 | use Wikibase\DataModel\Entity\PropertyId; |
||
| 9 | use Wikibase\DataModel\Serializers\PropertySerializer; |
||
| 10 | use Wikibase\DataModel\Snak\PropertyNoValueSnak; |
||
| 11 | use Wikibase\DataModel\Statement\StatementList; |
||
| 12 | use Wikibase\DataModel\Term\AliasGroupList; |
||
| 13 | use Wikibase\DataModel\Term\TermList; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @covers Wikibase\DataModel\Serializers\PropertySerializer |
||
| 17 | * |
||
| 18 | * @license GPL-2.0-or-later |
||
| 19 | * @author Thomas Pellissier Tanon |
||
| 20 | * @author Bene* < [email protected] > |
||
| 21 | */ |
||
| 22 | class PropertySerializerTest extends DispatchableSerializerTest { |
||
| 23 | |||
| 24 | protected function buildSerializer() { |
||
| 25 | $termListSerializerMock = $this->getMockBuilder( Serializer::class )->getMock(); |
||
| 26 | $termListSerializerMock->expects( $this->any() ) |
||
| 27 | ->method( 'serialize' ) |
||
| 28 | ->will( $this->returnCallback( function( TermList $termList ) { |
||
| 29 | if ( $termList->isEmpty() ) { |
||
| 30 | return []; |
||
| 31 | } |
||
| 32 | |||
| 33 | return [ |
||
| 34 | 'en' => [ 'lang' => 'en', 'value' => 'foo' ] |
||
| 35 | ]; |
||
| 36 | } ) ); |
||
| 37 | |||
| 38 | $aliasGroupListSerializerMock = $this->getMockBuilder( Serializer::class )->getMock(); |
||
| 39 | $aliasGroupListSerializerMock->expects( $this->any() ) |
||
| 40 | ->method( 'serialize' ) |
||
| 41 | ->will( $this->returnCallback( function( AliasGroupList $aliasGroupList ) { |
||
| 42 | if ( $aliasGroupList->isEmpty() ) { |
||
| 43 | return []; |
||
| 44 | } |
||
| 45 | |||
| 46 | return [ |
||
| 47 | 'en' => [ 'lang' => 'en', 'values' => [ 'foo', 'bar' ] ] |
||
| 48 | ]; |
||
| 49 | } ) ); |
||
| 50 | |||
| 51 | $statementListSerializerMock = $this->getMockBuilder( Serializer::class )->getMock(); |
||
| 52 | $statementListSerializerMock->expects( $this->any() ) |
||
| 53 | ->method( 'serialize' ) |
||
| 54 | ->will( $this->returnCallback( function( StatementList $statementList ) { |
||
| 55 | if ( $statementList->isEmpty() ) { |
||
| 56 | return []; |
||
| 57 | } |
||
| 58 | |||
| 59 | return [ |
||
| 60 | 'P42' => [ |
||
| 61 | [ |
||
| 62 | 'mainsnak' => [ |
||
| 63 | 'snaktype' => 'novalue', |
||
| 64 | 'property' => 'P42' |
||
| 65 | ], |
||
| 66 | 'type' => 'statement', |
||
| 67 | 'rank' => 'normal' |
||
| 68 | ] |
||
| 69 | ] |
||
| 70 | ]; |
||
| 71 | } ) ); |
||
| 72 | |||
| 73 | return new PropertySerializer( |
||
| 74 | $termListSerializerMock, |
||
|
0 ignored issues
–
show
|
|||
| 75 | $aliasGroupListSerializerMock, |
||
|
0 ignored issues
–
show
$aliasGroupListSerializerMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Serializers\Serializer>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 76 | $statementListSerializerMock |
||
|
0 ignored issues
–
show
$statementListSerializerMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Serializers\Serializer>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 77 | ); |
||
| 78 | } |
||
| 79 | |||
| 80 | public function serializableProvider() { |
||
| 81 | return [ |
||
| 82 | [ |
||
| 83 | Property::newFromType( 'string' ) |
||
| 84 | ], |
||
| 85 | ]; |
||
| 86 | } |
||
| 87 | |||
| 88 | public function nonSerializableProvider() { |
||
| 89 | return [ |
||
| 90 | [ |
||
| 91 | 5 |
||
| 92 | ], |
||
| 93 | [ |
||
| 94 | [] |
||
| 95 | ], |
||
| 96 | [ |
||
| 97 | new Item() |
||
| 98 | ], |
||
| 99 | ]; |
||
| 100 | } |
||
| 101 | |||
| 102 | public function serializationProvider() { |
||
| 103 | $property = Property::newFromType( 'string' ); |
||
| 104 | |||
| 105 | $provider = [ |
||
| 106 | [ |
||
| 107 | [ |
||
| 108 | 'type' => 'property', |
||
| 109 | 'datatype' => 'string', |
||
| 110 | 'labels' => [], |
||
| 111 | 'descriptions' => [], |
||
| 112 | 'aliases' => [], |
||
| 113 | 'claims' => [], |
||
| 114 | ], |
||
| 115 | $property |
||
| 116 | ], |
||
| 117 | ]; |
||
| 118 | |||
| 119 | $property = new Property( new PropertyId( 'P42' ), null, 'string' ); |
||
| 120 | $provider[] = [ |
||
| 121 | [ |
||
| 122 | 'type' => 'property', |
||
| 123 | 'datatype' => 'string', |
||
| 124 | 'id' => 'P42', |
||
| 125 | 'labels' => [], |
||
| 126 | 'descriptions' => [], |
||
| 127 | 'aliases' => [], |
||
| 128 | 'claims' => [], |
||
| 129 | ], |
||
| 130 | $property |
||
| 131 | ]; |
||
| 132 | |||
| 133 | $property = Property::newFromType( 'string' ); |
||
| 134 | $property->setLabel( 'en', 'foo' ); |
||
| 135 | $provider[] = [ |
||
| 136 | [ |
||
| 137 | 'type' => 'property', |
||
| 138 | 'datatype' => 'string', |
||
| 139 | 'labels' => [ |
||
| 140 | 'en' => [ |
||
| 141 | 'lang' => 'en', |
||
| 142 | 'value' => 'foo' |
||
| 143 | ] |
||
| 144 | ], |
||
| 145 | 'descriptions' => [], |
||
| 146 | 'aliases' => [], |
||
| 147 | 'claims' => [], |
||
| 148 | ], |
||
| 149 | $property |
||
| 150 | ]; |
||
| 151 | |||
| 152 | $property = Property::newFromType( 'string' ); |
||
| 153 | $property->setDescription( 'en', 'foo' ); |
||
| 154 | $provider[] = [ |
||
| 155 | [ |
||
| 156 | 'type' => 'property', |
||
| 157 | 'datatype' => 'string', |
||
| 158 | 'labels' => [], |
||
| 159 | 'descriptions' => [ |
||
| 160 | 'en' => [ |
||
| 161 | 'lang' => 'en', |
||
| 162 | 'value' => 'foo' |
||
| 163 | ] |
||
| 164 | ], |
||
| 165 | 'aliases' => [], |
||
| 166 | 'claims' => [], |
||
| 167 | ], |
||
| 168 | $property |
||
| 169 | ]; |
||
| 170 | |||
| 171 | $property = Property::newFromType( 'string' ); |
||
| 172 | $property->setAliases( 'en', [ 'foo', 'bar' ] ); |
||
| 173 | $provider[] = [ |
||
| 174 | [ |
||
| 175 | 'type' => 'property', |
||
| 176 | 'datatype' => 'string', |
||
| 177 | 'labels' => [], |
||
| 178 | 'descriptions' => [], |
||
| 179 | 'aliases' => [ |
||
| 180 | 'en' => [ |
||
| 181 | 'lang' => 'en', |
||
| 182 | 'values' => [ 'foo', 'bar' ] |
||
| 183 | ] |
||
| 184 | ], |
||
| 185 | 'claims' => [], |
||
| 186 | ], |
||
| 187 | $property |
||
| 188 | ]; |
||
| 189 | |||
| 190 | $property = Property::newFromType( 'string' ); |
||
| 191 | $property->getStatements()->addNewStatement( new PropertyNoValueSnak( 42 ), null, null, 'test' ); |
||
| 192 | $provider[] = [ |
||
| 193 | [ |
||
| 194 | 'type' => 'property', |
||
| 195 | 'datatype' => 'string', |
||
| 196 | 'labels' => [], |
||
| 197 | 'descriptions' => [], |
||
| 198 | 'aliases' => [], |
||
| 199 | 'claims' => [ |
||
| 200 | 'P42' => [ |
||
| 201 | [ |
||
| 202 | 'mainsnak' => [ |
||
| 203 | 'snaktype' => 'novalue', |
||
| 204 | 'property' => 'P42' |
||
| 205 | ], |
||
| 206 | 'type' => 'statement', |
||
| 207 | 'rank' => 'normal' |
||
| 208 | ] |
||
| 209 | ] |
||
| 210 | ], |
||
| 211 | ], |
||
| 212 | $property |
||
| 213 | ]; |
||
| 214 | |||
| 215 | return $provider; |
||
| 216 | } |
||
| 217 | |||
| 218 | } |
||
| 219 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: