Skip to content

Commit

Permalink
Merge "Merge (de)serialization of constraint/property scopes"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Jun 26, 2018
2 parents 3406575 + 0ecee06 commit ed051fe
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 210 deletions.
51 changes: 11 additions & 40 deletions src/ConstraintCheck/Message/ViolationMessageDeserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ private function deserializeArgument( ViolationMessage $message, array $serializ
ViolationMessage::TYPE_DATA_VALUE => 'deserializeDataValue',
ViolationMessage::TYPE_DATA_VALUE_TYPE => 'deserializeStringByIdentity',
ViolationMessage::TYPE_INLINE_CODE => 'deserializeStringByIdentity',
ViolationMessage::TYPE_CONSTRAINT_SCOPE => 'deserializeConstraintScope',
ViolationMessage::TYPE_CONSTRAINT_SCOPE_LIST => 'deserializeConstraintScopeList',
ViolationMessage::TYPE_PROPERTY_SCOPE => 'deserializePropertyScope',
ViolationMessage::TYPE_PROPERTY_SCOPE_LIST => 'deserializePropertyScopeList',
ViolationMessage::TYPE_CONSTRAINT_SCOPE => 'deserializeContextType',
ViolationMessage::TYPE_CONSTRAINT_SCOPE_LIST => 'deserializeContextTypeList',
ViolationMessage::TYPE_PROPERTY_SCOPE => 'deserializeContextType',
ViolationMessage::TYPE_PROPERTY_SCOPE_LIST => 'deserializeContextTypeList',
ViolationMessage::TYPE_LANGUAGE => 'deserializeStringByIdentity',
ViolationMessage::TYPE_MULTILINGUAL_TEXT => 'deserializeMultilingualText',
];
Expand Down Expand Up @@ -155,11 +155,11 @@ private function deserializeDataValue( array $dataValueSerialization ) {
}

/**
* @param string $scopeAbbreviation
* @param string $contextTypeAbbreviation
* @return string one of the Context::TYPE_* constants
*/
private function deserializeConstraintScope( $scopeAbbreviation ) {
switch ( $scopeAbbreviation ) {
private function deserializeContextType( $contextTypeAbbreviation ) {
switch ( $contextTypeAbbreviation ) {
case 's':
return Context::TYPE_STATEMENT;
case 'q':
Expand All @@ -169,47 +169,18 @@ private function deserializeConstraintScope( $scopeAbbreviation ) {
default:
// @codeCoverageIgnoreStart
throw new LogicException(
'Unknown constraint scope abbreviation ' . $scopeAbbreviation
'Unknown context type abbreviation ' . $contextTypeAbbreviation
);
// @codeCoverageIgnoreEnd
}
}

/**
* @param string[] $scopeAbbreviations
* @param string[] $contextTypeAbbreviations
* @return string[] Context::TYPE_* constants
*/
private function deserializeConstraintScopeList( array $scopeAbbreviations ) {
return array_map( [ $this, 'deserializeConstraintScope' ], $scopeAbbreviations );
}

/**
* @param string $scopeAbbreviation
* @return string one of the Context::TYPE_* constants
*/
private function deserializePropertyScope( $scopeAbbreviation ) {
switch ( $scopeAbbreviation ) {
case 's':
return Context::TYPE_STATEMENT;
case 'q':
return Context::TYPE_QUALIFIER;
case 'r':
return Context::TYPE_REFERENCE;
default:
// @codeCoverageIgnoreStart
throw new LogicException(
'Unknown property scope abbreviation ' . $scopeAbbreviation
);
// @codeCoverageIgnoreEnd
}
}

/**
* @param string[] $scopeAbbreviations
* @return string[] Context::TYPE_* constants
*/
private function deserializePropertyScopeList( array $scopeAbbreviations ) {
return array_map( [ $this, 'deserializePropertyScope' ], $scopeAbbreviations );
private function deserializeContextTypeList( array $contextTypeAbbreviations ) {
return array_map( [ $this, 'deserializeContextType' ], $contextTypeAbbreviations );
}

/**
Expand Down
55 changes: 13 additions & 42 deletions src/ConstraintCheck/Message/ViolationMessageSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ private function serializeArgument( array $argument ) {
ViolationMessage::TYPE_DATA_VALUE => 'serializeDataValue',
ViolationMessage::TYPE_DATA_VALUE_TYPE => 'serializeStringByIdentity',
ViolationMessage::TYPE_INLINE_CODE => 'serializeStringByIdentity',
ViolationMessage::TYPE_CONSTRAINT_SCOPE => 'serializeConstraintScope',
ViolationMessage::TYPE_CONSTRAINT_SCOPE_LIST => 'serializeConstraintScopeList',
ViolationMessage::TYPE_PROPERTY_SCOPE => 'serializePropertyScope',
ViolationMessage::TYPE_PROPERTY_SCOPE_LIST => 'serializePropertyScopeList',
ViolationMessage::TYPE_CONSTRAINT_SCOPE => 'serializeContextType',
ViolationMessage::TYPE_CONSTRAINT_SCOPE_LIST => 'serializeContextTypeList',
ViolationMessage::TYPE_PROPERTY_SCOPE => 'serializeContextType',
ViolationMessage::TYPE_PROPERTY_SCOPE_LIST => 'serializeContextTypeList',
ViolationMessage::TYPE_LANGUAGE => 'serializeStringByIdentity',
ViolationMessage::TYPE_MULTILINGUAL_TEXT => 'serializeMultilingualText',
];
Expand Down Expand Up @@ -150,11 +150,11 @@ private function serializeDataValue( DataValue $dataValue ) {
}

/**
* @param string $scope one of the Context::TYPE_* constants
* @return string the abbreviated scope
* @param string $contextType one of the Context::TYPE_* constants
* @return string the abbreviated context type
*/
private function serializeConstraintScope( $scope ) {
switch ( $scope ) {
private function serializeContextType( $contextType ) {
switch ( $contextType ) {
case Context::TYPE_STATEMENT:
return 's';
case Context::TYPE_QUALIFIER:
Expand All @@ -164,47 +164,18 @@ private function serializeConstraintScope( $scope ) {
default:
// @codeCoverageIgnoreStart
throw new LogicException(
'Unknown constraint scope ' . $scope
'Unknown context type ' . $contextType
);
// @codeCoverageIgnoreEnd
}
}

/**
* @param string[] $scopeList Context::TYPE_* constants
* @return string[] abbreviated scopes
* @param string[] $contextTypeList Context::TYPE_* constants
* @return string[] abbreviated context types
*/
private function serializeConstraintScopeList( array $scopeList ) {
return array_map( [ $this, 'serializeConstraintScope' ], $scopeList );
}

/**
* @param string $scope one of the Context::TYPE_* constants
* @return string the abbreviated scope
*/
private function serializePropertyScope( $scope ) {
switch ( $scope ) {
case Context::TYPE_STATEMENT:
return 's';
case Context::TYPE_QUALIFIER:
return 'q';
case Context::TYPE_REFERENCE:
return 'r';
default:
// @codeCoverageIgnoreStart
throw new LogicException(
'Unknown property scope ' . $scope
);
// @codeCoverageIgnoreEnd
}
}

/**
* @param string[] $scopeList Context::TYPE_* constants
* @return string[] abbreviated scopes
*/
private function serializePropertyScopeList( array $scopeList ) {
return array_map( [ $this, 'serializePropertyScope' ], $scopeList );
private function serializeContextTypeList( array $contextTypeList ) {
return array_map( [ $this, 'serializeContextType' ], $contextTypeList );
}

/**
Expand Down
76 changes: 12 additions & 64 deletions tests/phpunit/Message/ViolationMessageDeserializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,19 +264,19 @@ public function testDeserializeDataValue() {
}

/**
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageDeserializer::deserializeConstraintScope
* @dataProvider provideConstraintScopeAbbreviations
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageDeserializer::deserializeContextType
* @dataProvider provideContextTypeAbbreviations
*/
public function testDeserializeConstraintScope( $abbreviation, $scope ) {
public function testDeserializeContextType( $abbreviation, $contextType ) {
$deserializer = $this->getViolationMessageDeserializer();

$deserialized = TestingAccessWrapper::newFromObject( $deserializer )
->deserializeConstraintScope( $abbreviation );
->deserializeContextType( $abbreviation );

$this->assertSame( $scope, $deserialized );
$this->assertSame( $contextType, $deserialized );
}

public function provideConstraintScopeAbbreviations() {
public function provideContextTypeAbbreviations() {
return [
[ 's', Context::TYPE_STATEMENT ],
[ 'q', Context::TYPE_QUALIFIER ],
Expand All @@ -285,14 +285,14 @@ public function provideConstraintScopeAbbreviations() {
}

/**
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageDeserializer::deserializeConstraintScopeList
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageDeserializer::deserializeContextTypeList
*/
public function testDeserializeConstraintScopeList() {
public function testDeserializeContextTypeList() {
$serializations = [ 's', 'r', 'q' ];
$deserializer = $this->getViolationMessageDeserializer();

$deserialized = TestingAccessWrapper::newFromObject( $deserializer )
->deserializeConstraintScopeList( $serializations );
->deserializeContextTypeList( $serializations );

$expected = [
Context::TYPE_STATEMENT,
Expand All @@ -303,66 +303,14 @@ public function testDeserializeConstraintScopeList() {
}

/**
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageDeserializer::deserializeConstraintScopeList
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageDeserializer::deserializeContextTypeList
*/
public function testDeserializeConstraintScopeList_empty() {
public function testDeserializeContextTypeList_empty() {
$serializations = [];
$deserializer = $this->getViolationMessageDeserializer();

$deserialized = TestingAccessWrapper::newFromObject( $deserializer )
->deserializeConstraintScopeList( $serializations );

$this->assertSame( [], $deserialized );
}

/**
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageDeserializer::deserializePropertyScope
* @dataProvider providePropertyScopeAbbreviations
*/
public function testDeserializePropertyScope( $abbreviation, $scope ) {
$deserializer = $this->getViolationMessageDeserializer();

$deserialized = TestingAccessWrapper::newFromObject( $deserializer )
->deserializePropertyScope( $abbreviation );

$this->assertSame( $scope, $deserialized );
}

public function providePropertyScopeAbbreviations() {
return [
[ 's', Context::TYPE_STATEMENT ],
[ 'q', Context::TYPE_QUALIFIER ],
[ 'r', Context::TYPE_REFERENCE ],
];
}

/**
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageDeserializer::deserializePropertyScopeList
*/
public function testDeserializePropertyScopeList() {
$serializations = [ 's', 'r', 'q' ];
$deserializer = $this->getViolationMessageDeserializer();

$deserialized = TestingAccessWrapper::newFromObject( $deserializer )
->deserializePropertyScopeList( $serializations );

$expected = [
Context::TYPE_STATEMENT,
Context::TYPE_REFERENCE,
Context::TYPE_QUALIFIER,
];
$this->assertSame( $expected, $deserialized );
}

/**
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageDeserializer::deserializePropertyScopeList
*/
public function testDeserializePropertyScopeList_empty() {
$serializations = [];
$deserializer = $this->getViolationMessageDeserializer();

$deserialized = TestingAccessWrapper::newFromObject( $deserializer )
->deserializePropertyScopeList( $serializations );
->deserializeContextTypeList( $serializations );

$this->assertSame( [], $deserialized );
}
Expand Down
77 changes: 13 additions & 64 deletions tests/phpunit/Message/ViolationMessageSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,19 @@ public function testSerializeDataValue() {
}

/**
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageSerializer::serializeConstraintScope
* @dataProvider provideConstraintScopes
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageSerializer::serializeContextType
* @dataProvider provideContextTypes
*/
public function testSerializeConstraintScope( $scope, $abbreviation ) {
public function testSerializeContextType( $contextType, $abbreviation ) {
$serializer = new ViolationMessageSerializer();

$serialized = TestingAccessWrapper::newFromObject( $serializer )
->serializeConstraintScope( $scope );
->serializeContextType( $contextType );

$this->assertSame( $abbreviation, $serialized );
}

public function provideConstraintScopes() {
public function provideContextTypes() {
return [
[ Context::TYPE_STATEMENT, 's' ],
[ Context::TYPE_QUALIFIER, 'q' ],
Expand All @@ -263,82 +263,31 @@ public function provideConstraintScopes() {
}

/**
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageSerializer::serializeConstraintScopeList
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageSerializer::serializeContextTypeList
*/
public function testSerializeConstraintScopeList() {
$scopeList = [
public function testSerializeContextTypeList() {
$contextTypeList = [
Context::TYPE_STATEMENT,
Context::TYPE_REFERENCE,
Context::TYPE_QUALIFIER,
];
$serializer = new ViolationMessageSerializer();

$serialized = TestingAccessWrapper::newFromObject( $serializer )
->serializeConstraintScopeList( $scopeList );
->serializeContextTypeList( $contextTypeList );

$this->assertSame( [ 's', 'r', 'q' ], $serialized );
}

/**
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageSerializer::serializeConstraintScopeList
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageSerializer::serializeContextTypeList
*/
public function testSerializeConstraintScopeList_empty() {
$scopeList = [];
public function testSerializeContextTypeList_empty() {
$contextTypeList = [];
$serializer = new ViolationMessageSerializer();

$serialized = TestingAccessWrapper::newFromObject( $serializer )
->serializeConstraintScopeList( $scopeList );

$this->assertSame( [], $serialized );
}

/**
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageSerializer::serializePropertyScope
* @dataProvider providePropertyScopes
*/
public function testSerializePropertyScope( $scope, $abbreviation ) {
$serializer = new ViolationMessageSerializer();

$serialized = TestingAccessWrapper::newFromObject( $serializer )
->serializePropertyScope( $scope );

$this->assertSame( $abbreviation, $serialized );
}

public function providePropertyScopes() {
return [
[ Context::TYPE_STATEMENT, 's' ],
[ Context::TYPE_QUALIFIER, 'q' ],
[ Context::TYPE_REFERENCE, 'r' ],
];
}

/**
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageSerializer::serializePropertyScopeList
*/
public function testSerializePropertyScopeList() {
$scopeList = [
Context::TYPE_STATEMENT,
Context::TYPE_REFERENCE,
Context::TYPE_QUALIFIER,
];
$serializer = new ViolationMessageSerializer();

$serialized = TestingAccessWrapper::newFromObject( $serializer )
->serializePropertyScopeList( $scopeList );

$this->assertSame( [ 's', 'r', 'q' ], $serialized );
}

/**
* @covers WikibaseQuality\ConstraintReport\ConstraintCheck\Message\ViolationMessageSerializer::serializePropertyScopeList
*/
public function testSerializePropertyScopeList_empty() {
$scopeList = [];
$serializer = new ViolationMessageSerializer();

$serialized = TestingAccessWrapper::newFromObject( $serializer )
->serializePropertyScopeList( $scopeList );
->serializeContextTypeList( $contextTypeList );

$this->assertSame( [], $serialized );
}
Expand Down

0 comments on commit ed051fe

Please sign in to comment.