Re: [SMW-devel] SMWQueryResult mock object for testing SemanticResultFormat
Hey, I concur with James on avoiding using SMWQueryResult in your tests directly. This class has many issues, most notably that it pretends to be some kind of Value Object, while actually not containing the data, but rather depending on services bound to persistence and framework to retrieve the data. I ran into this issue in 2013 and wrote some mails about it [0] and then some rudimentary alternative [1] that might now serve as inspiration. Generally speaking it should be possible to just give your result printer a value object with the data it should display, and then assert that it returns the correct stuff, in a functional manner, without any services being involved, be them persistence services or otherwise. [0] wikimedia.7.x6.nabble.com/Query-result-rewrite-td5015574.html [1] https://github.com/JeroenDeDauw/CheckedTable/tree/master/src/SMW/Query/Result Cheers -- Jeroen De Dauw | https://entropywins.wtf | https://keybase.io/jeroendedauw Software craftsmanship advocate | Developer at Wikimedia Germany ~=[,,_,,]:3 -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] SMWQueryResult mock object for testing SemanticResultFormat
Hi, > CoreMockObjectRepository Class [4] but could not find an example how to > create a mock for SMWQueryResult. Please avoid using this object, it was created in the past and has since been considered to be deprecated with any remaining consumers to be converted in future. > @mwjames: any ideas suggestions from your side? In anticipation that I find time during the weekend, I will comment on [0]. PS: Classes marked with @private annotation [1] are not be considered for use outside of SMW-core. [0] https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/2589 [1] https://www.semantic-mediawiki.org/wiki/Coding_conventions#Class_annotations Cheers On 8/3/17, planetenxinwrote: > I want to enhance existing SRF graph format test. My idea is, to create > a mock SMWQueryResult (=test data) that will be passed to function > getResultText (at the moment, could be getGraphvizCode or something later). > > I had a look at existing tests [1] and docs [2][3] as well as > CoreMockObjectRepository Class [4] but could not find an example how to > create a mock for SMWQueryResult. > > Is creating a mock for SMWQueryResult a good idea at all? > > Could someone help with an example? > > Many thx! > > [1] > https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Unit/Formats > [2] https://www.semantic-mediawiki.org/wiki/Help:Using_mock_objects > [3] > https://www.semantic-mediawiki.org/wiki/Writing_result_printers#Writing_tests > [4] > https://doc.semantic-mediawiki.org/classSMW_1_1Tests_1_1Utils_1_1Mock_1_1CoreMockObjectRepository.html#a0346be0a0d6284eaea8e79228455ac09 > > -- > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > ___ > Semediawiki-devel mailing list > Semediawiki-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/semediawiki-devel > -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] SMWQueryResult mock object for testing SemanticResultFormat
roundtrip example $sf = new SerializerFactory(); $queryResultJSON = json_encode( $sf->getSerializerFor( $queryResult )->serialize( $queryResult ) ); $decodedQueryResult = json_decode( $queryResultJSON ); $queryResultFromJSON = $sf->getDeserializerFor( $decodedQueryResult )->deserialize( $decodedQueryResult ); Am 03.08.2017 um 15:05 schrieb planetenxin: > found > > https://doc.semantic-mediawiki.org/classSMW_1_1Serializers_1_1QueryResultSerializer.html > > Let's see if this can be used... -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] SMWQueryResult mock object for testing SemanticResultFormat
found https://doc.semantic-mediawiki.org/classSMW_1_1Serializers_1_1QueryResultSerializer.html Let's see if this can be used... Am 03.08.2017 um 14:37 schrieb planetenxin: > Another option would be json_encode / json_decode but this would require > implementing JsonSerializable interface as far as I can see. -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] SMWQueryResult mock object for testing SemanticResultFormat
Another option would be json_encode / json_decode but this would require implementing JsonSerializable interface as far as I can see. @mwjames: any ideas suggestions from your side? Am 03.08.2017 um 12:46 schrieb Stephan Gambke: > Although, i just found a class QueryFactory, that has a function > newQueryResult( Store $store, Query $query, $results = array(), > $continue = false ) that might be of use. > Maybe James HK has a better idea. -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] SMWQueryResult mock object for testing SemanticResultFormat
Stephan, thanks for your feedback. In the meanwhile I had another idea. How about creating test data from serialized SMWQueryResults? I saw, that SMWQueryResult provides a serializeToArray() function [1]. Is there an easy way to "unserializeFromArray()"? [1] https://doc.semantic-mediawiki.org/classSMWQueryResult.html#a275ce1f7f02fe2e13ad73f49512185b6 Am 03.08.2017 um 09:58 schrieb Stephan Gambke: > Yes, SRF does not have a lot of testing, so thx for improving and sorry > for not having much to copy from! Maybe [0] could give you an idea on > how to create your mock object. See [1] for documentation on how to work > with mock objects. > > Cheers > Stephan > > [0] > https://github.com/SemanticMediaWiki/SemanticResultFormats/blob/master/tests/phpunit/Unit/Formats/TreeTest.php#L56 > > > > [1] > https://phpunit.de/manual/4.8/en/test-doubles.html#test-doubles.mock-objects > -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] SMWQueryResult mock object for testing SemanticResultFormat
Yes, SRF does not have a lot of testing, so thx for improving and sorry for not having much to copy from! Maybe [0] could give you an idea on how to create your mock object. See [1] for documentation on how to work with mock objects. Cheers Stephan [0] https://github.com/SemanticMediaWiki/SemanticResultFormats/blob/master/tests/phpunit/Unit/Formats/TreeTest.php#L56 [1] https://phpunit.de/manual/4.8/en/test-doubles.html#test-doubles.mock-objects > Original Message > Subject: [SMW-devel] SMWQueryResult mock object for testing > SemanticResultFormat > Local Time: August 3, 2017 9:40 AM > UTC Time: August 3, 2017 7:40 AM > From: planeten...@web.de > To: Semediawiki-devel@lists.sourceforge.net > I want to enhance existing SRF graph format test. My idea is, to create > a mock SMWQueryResult (=test data) that will be passed to function > getResultText (at the moment, could be getGraphvizCode or something later). > I had a look at existing tests [1] and docs [2][3] as well as > CoreMockObjectRepository Class [4] but could not find an example how to > create a mock for SMWQueryResult. > Is creating a mock for SMWQueryResult a good idea at all? > Could someone help with an example? > Many thx! > [1] > https://github.com/SemanticMediaWiki/SemanticResultFormats/tree/master/tests/phpunit/Unit/Formats > [2] https://www.semantic-mediawiki.org/wiki/Help:Using_mock_objects > [3] > https://www.semantic-mediawiki.org/wiki/Writing_result_printers#Writing_tests > [4] > https://doc.semantic-mediawiki.org/classSMW_1_1Tests_1_1Utils_1_1Mock_1_1CoreMockObjectRepository.html#a0346be0a0d6284eaea8e79228455ac09 > -- > Check out the vibrant tech community on one of the world"s most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > ___ > Semediawiki-devel mailing list > Semediawiki-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/semediawiki-devel-- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel