jenkins-bot has submitted this change and it was merged. Change subject: Ground work for QueryEntity serialization and deserialization ......................................................................
Ground work for QueryEntity serialization and deserialization Change-Id: Ie301acfee48c3f525fef10bd46856521db29ea86 --- A Tests/Phpunit/Wikibase/Query/QueryEntityDeserializerTest.php A Tests/Phpunit/Wikibase/Query/QueryEntitySerializerTest.php A src/Wikibase/Query/QueryEntityDeserializer.php A src/Wikibase/Query/QueryEntitySerializer.php 4 files changed, 139 insertions(+), 0 deletions(-) Approvals: Denny Vrandecic: Looks good to me, approved jenkins-bot: Verified diff --git a/Tests/Phpunit/Wikibase/Query/QueryEntityDeserializerTest.php b/Tests/Phpunit/Wikibase/Query/QueryEntityDeserializerTest.php new file mode 100644 index 0000000..7861de6 --- /dev/null +++ b/Tests/Phpunit/Wikibase/Query/QueryEntityDeserializerTest.php @@ -0,0 +1,25 @@ +<?php + +namespace Tests\Phpunit\Wikibase\Query; + +use Wikibase\Query\QueryEntityDeserializer; + +/** + * @covers Wikibase\Query\QueryEntityDeserializer + * + * @file + * @ingroup WikibaseQuery + * @group WikibaseQuery + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + * @author Adam Shorland < adamshorl...@gmail.com > + */ +class QueryEntityDeserializerTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + new QueryEntityDeserializer(); + $this->assertFalse( false ); + } + +} diff --git a/Tests/Phpunit/Wikibase/Query/QueryEntitySerializerTest.php b/Tests/Phpunit/Wikibase/Query/QueryEntitySerializerTest.php new file mode 100644 index 0000000..0797d74 --- /dev/null +++ b/Tests/Phpunit/Wikibase/Query/QueryEntitySerializerTest.php @@ -0,0 +1,60 @@ +<?php + +namespace Tests\Phpunit\Wikibase\Query; + +use Ask\Language\Description\AnyValue; +use Ask\Language\Option\QueryOptions; +use Ask\Language\Query; +use Wikibase\Query\QueryEntity; +use Wikibase\Query\QueryEntitySerializer; + +/** + * @covers Wikibase\Query\QueryEntitySerializer + * + * @file + * @ingroup WikibaseQuery + * @group WikibaseQuery + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + * @author Adam Shorland < adamshorl...@gmail.com > + */ +class QueryEntitySerializerTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + new QueryEntitySerializer( $this->getMock( 'Serializers\Serializer' ) ); + $this->assertFalse( false ); + } + + public function testSerializationCallsQuerySerialization() { + $querySerializer = $this->getMock( 'Serializers\Serializer' ); + + $queryEntity = $this->newSimpleEntity(); + $mockSerialization = 'query serialization'; + + $querySerializer->expects( $this->once() ) + ->method( 'serialize' ) + ->with( $this->equalTo( $queryEntity ) ) + ->will( $this->returnValue( $mockSerialization ) ); + + $serializer = new QueryEntitySerializer( $querySerializer ); + + $serialization = $serializer->serialize( $queryEntity ); + + $this->assertArrayHasKey( 'query', $serialization ); + $this->assertEquals( $mockSerialization, $serialization['query'] ); + } + + protected function newSimpleEntity() { + return new QueryEntity( $this->newQuery() ); + } + + protected function newQuery() { + return new Query( + new AnyValue(), + array(), + new QueryOptions( 1, 0 ) + ); + } + +} diff --git a/src/Wikibase/Query/QueryEntityDeserializer.php b/src/Wikibase/Query/QueryEntityDeserializer.php new file mode 100644 index 0000000..14be902 --- /dev/null +++ b/src/Wikibase/Query/QueryEntityDeserializer.php @@ -0,0 +1,19 @@ +<?php + +namespace Wikibase\Query; + +/** + * @since 1.0 + * + * @file + * @ingroup WikibaseQuery + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + * @author Adam Shorland < adamshorl...@gmail.com > + */ +class QueryEntityDeserializer { + + // TODO + +} diff --git a/src/Wikibase/Query/QueryEntitySerializer.php b/src/Wikibase/Query/QueryEntitySerializer.php new file mode 100644 index 0000000..7a549b6 --- /dev/null +++ b/src/Wikibase/Query/QueryEntitySerializer.php @@ -0,0 +1,35 @@ +<?php + +namespace Wikibase\Query; + +use Serializers\Serializer; + +/** + * @since 1.0 + * + * @file + * @ingroup WikibaseQuery + * + * @licence GNU GPL v2+ + * @author Jeroen De Dauw < jeroended...@gmail.com > + * @author Adam Shorland < adamshorl...@gmail.com > + */ +class QueryEntitySerializer { + + protected $querySerializer; + + public function __construct( Serializer $querySerializer ) { + $this->querySerializer = $querySerializer; + } + + public function serialize( $queryEntity ) { + $querySerialization = $this->querySerializer->serialize( $queryEntity ); + + return array( + 'query' => $querySerialization + ); + } + + // TODO + +} -- To view, visit https://gerrit.wikimedia.org/r/75340 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ie301acfee48c3f525fef10bd46856521db29ea86 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseQuery Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: Denny Vrandecic <denny.vrande...@wikimedia.de> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits