Skip to content

Commit

Permalink
Merge pull request #181 from oat-sa/release-6.3.0
Browse files Browse the repository at this point in the history
Release 6.3.0
  • Loading branch information
zagovorichev authored Jun 23, 2017
2 parents fd72a4b + e52837f commit 48e08b6
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 154 deletions.
2 changes: 1 addition & 1 deletion manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
'label' => 'Test core extension',
'description' => 'TAO Tests extension contains the abstraction of the test-runners, but requires an implementation in order to be able to run tests',
'license' => 'GPL-2.0',
'version' => '6.2.0',
'version' => '6.3.0',
'author' => 'Open Assessment Technologies, CRP Henri Tudor',
'requires' => array(
'taoItems' => '>=2.20.1',
Expand Down
34 changes: 0 additions & 34 deletions models/classes/class.TestsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,40 +389,6 @@ public function getTestModelImplementation(core_kernel_classes_Resource $testMod
return $testModelService;
}

/**
* Get the core_kernel_file_File object corresponding to the content of $test.
*
* @deprecated test content is managed by the respective test model
*
* @param core_kernel_classes_Resource $test A resource corresponding to a TAO Test in the Knowledge Base.
* @throws common_exception_Error If an error occurs while retrieving the test content.
* @return core_kernel_file_File
*/
public function getTestContent(core_kernel_classes_Resource $test)
{
$testContentProperty = new core_kernel_classes_Property(self::TEST_TESTCONTENT_PROP);
try {
$testcontent = $test->getUniquePropertyValue($testContentProperty);
} catch (common_exception_EmptyProperty $e) {
$uri = $test->getUri();
$msg = "Test '${uri}' has no content.";
throw new common_exception_Error($msg);
} catch (common_Exception $e) {
$uri = $test->getUri();
$msg = "Multiple contents found for test '${uri}'.";
throw new common_exception_Error($msg);
}
if ($testcontent instanceof core_kernel_classes_Resource) {

return new core_kernel_file_File($testcontent->getUri());
} else {
$uri = $test->getUri();
$msg = "Test '${uri}' content is not a resource. " . $testcontent;
common_Logger::w($msg);
return $testcontent;
}
}

/**
* Get serializer to persist filesystem object
*
Expand Down
43 changes: 43 additions & 0 deletions models/classes/runner/time/ArraySerializable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2017 (original work) Open Assessment Technologies SA ;
*
*/
/**
* @author Jean-Sébastien Conan <jean-sebastien@taotesting.com>
*/

namespace oat\taoTests\models\runner\time;

/**
* Interface ArraySerializable
* @package oat\taoTests\models\classes\runner\time
*/
interface ArraySerializable
{
/**
* Exports the internal state to an array
* @return array
*/
public function toArray();

/**
* Imports the internal state from an array
* @param array $data
*/
public function fromArray($data);
}
2 changes: 1 addition & 1 deletion models/classes/runner/time/TimeLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @package oat\taoTests\models\runner\time
*/
interface TimeLine extends \Serializable
interface TimeLine
{
/**
* Gets the list of TimePoint present in the TimeLine
Expand Down
63 changes: 45 additions & 18 deletions models/classes/runner/time/TimePoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @package oat\taoTests\models\runner\time
*/
class TimePoint implements \Serializable
class TimePoint implements ArraySerializable, \Serializable, \JsonSerializable
{
/**
* Type of TimePoint: start of range
Expand Down Expand Up @@ -126,35 +126,25 @@ public function __construct($tags = null, $timestamp = null, $type = null, $targ
}

/**
* String representation of object
* @link http://php.net/manual/en/serializable.serialize.php
* @return string the string representation of the object or null
* @since 5.1.0
* Exports the internal state to an array
* @return array
*/
public function serialize()
public function toArray()
{
$data = [
return [
'ts' => $this->getTimestamp(),
'type' => $this->getType(),
'target' => $this->getTarget(),
'tags' => $this->getTags(),
];
return serialize($data);
}

/**
* Constructs the object
* @link http://php.net/manual/en/serializable.unserialize.php
* @param string $serialized <p>
* The string representation of the object.
* </p>
* @return void
* @since 5.1.0
* Imports the internal state from an array
* @param array $data
*/
public function unserialize($serialized)
public function fromArray($data)
{
$data = unserialize($serialized);

if ($data) {
if (isset($data['tags'])) {
$this->setTags($data['tags']);
Expand All @@ -174,6 +164,43 @@ public function unserialize($serialized)
}
}

/**
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize()
{
return $this->toArray();
}

/**
* String representation of object
* @link http://php.net/manual/en/serializable.serialize.php
* @return string the string representation of the object or null
* @since 5.1.0
*/
public function serialize()
{
return serialize($this->toArray());
}

/**
* Constructs the object
* @link http://php.net/manual/en/serializable.unserialize.php
* @param string $serialized <p>
* The string representation of the object.
* </p>
* @return void
* @since 5.1.0
*/
public function unserialize($serialized)
{
$this->fromArray(unserialize($serialized));
}

/**
* Sets the timestamp of the TimePoint
* @param float $timestamp
Expand Down
2 changes: 1 addition & 1 deletion scripts/update/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ public function update($initialVersion)
$this->setVersion('6.0.1');
}

$this->skip('6.0.1', '6.2.0');
$this->skip('6.0.1', '6.3.0');
}
}
84 changes: 0 additions & 84 deletions test/TestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,90 +274,6 @@ public function testCloneInstance($testInstance) {
return $clone;
}

/**
* @param $test
* @return \core_kernel_file_File
*/
public function testGetTestContent() {

$testContentProperty = new core_kernel_classes_Property(taoTests_models_classes_TestsService::TEST_TESTCONTENT_PROP);

$prophet = new Prophet();
$testProphecy = $prophet->prophesize('core_kernel_classes_Resource');
$testContentProphcy = $prophet->prophesize('core_kernel_classes_Resource');
$testContentProphcy->getUri()->willReturn('#fakeUri');
$testContent = $testContentProphcy->reveal();

$testProphecy->getUniquePropertyValue($testContentProperty)->willReturn($testContent);

$test = $testProphecy->reveal();

$result = $this->testsService->getTestContent($test);

$this->assertInstanceOf('core_kernel_file_File', $result);
$this->assertEquals('#fakeUri', $result->getUri());

$testProphecy = $prophet->prophesize('core_kernel_classes_Resource');
$testProphecy->getUniquePropertyValue($testContentProperty)->willReturn(null);
$testProphecy->getUri()->willReturn('#fakeUri');
$test = $testProphecy->reveal();
$result = $this->testsService->getTestContent($test);
$this->assertNull($result);


}
/**
*
* @author Lionel Lecaque, lionel@taotesting.com
*/
public function testGetTestContentEmtpty()
{
$testContentProperty = new core_kernel_classes_Property(taoTests_models_classes_TestsService::TEST_TESTCONTENT_PROP);

$prophet = new Prophet();
$testProphecy = $prophet->prophesize('core_kernel_classes_Resource');
$testProphecy
->getUniquePropertyValue($testContentProperty)
->willThrow('\core_kernel_classes_EmptyProperty');
$testProphecy->getUri()->willReturn('#fakeUri');
$test = $testProphecy->reveal();

try {
$result = $this->testsService->getTestContent($test);
}
catch(\Exception $e){
$this->assertInstanceOf('common_exception_Error', $e);
$this->assertEquals("Test '#fakeUri' has no content.", $e->getMessage());
}

}

/**
*
* @author Lionel Lecaque, lionel@taotesting.com
*/
public function testGetTestContentNoContent()
{
$testContentProperty = new core_kernel_classes_Property(taoTests_models_classes_TestsService::TEST_TESTCONTENT_PROP);

$prophet = new Prophet();
$testProphecy = $prophet->prophesize('core_kernel_classes_Resource');
$testProphecy
->getUniquePropertyValue($testContentProperty)
->willThrow('\common_Exception');
$testProphecy->getUri()->willReturn('#fakeUri');
$test = $testProphecy->reveal();

try {
$result = $this->testsService->getTestContent($test);
}
catch(\Exception $e){
$this->assertInstanceOf('common_exception_Error', $e);
$this->assertEquals("Multiple contents found for test '#fakeUri'.", $e->getMessage());
}

}

/**
* @depends testSubTest
* @param $subTest
Expand Down
4 changes: 0 additions & 4 deletions test/pack/PackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ public function testPack(){
->method('getTestModel')
->will($this->returnValue(new core_kernel_classes_Resource('fooModel')));

$serviceMock
->method('getTestContent')
->will($this->returnValue(''));

$serviceMock
->method('getTestModelImplementation')
->with($this->equalTo($model))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use oat\tao\test\TaoPhpUnitTestRunner;
use oat\taoTests\models\runner\time\TimePoint;

class TimerPointTest extends TaoPhpUnitTestRunner
class TimePointTest extends TaoPhpUnitTestRunner
{
/**
* tests initialization
Expand All @@ -36,6 +36,73 @@ public function setUp()
TaoPhpUnitTestRunner::initTest();
}

/**
* @dataProvider testSerializeProvider
* @param $tags
* @param $timestamp
* @param $type
* @param $target
*/
public function testJsonSerialize($tags, $timestamp, $type, $target)
{
$timePoint = new TimePoint($tags, $timestamp, $type, $target);
$data = $timePoint->jsonSerialize();

$this->assertEquals($timePoint->getTimestamp(), $data['ts']);
$this->assertEquals($timePoint->getTarget(), $data['target']);
$this->assertEquals($timePoint->getTags(), $data['tags']);
$this->assertEquals($timePoint->getType(), $data['type']);
$this->assertEquals(json_encode($data), json_encode($timePoint));
}

/**
* @dataProvider testSerializeProvider
* @param $tags
* @param $timestamp
* @param $type
* @param $target
*/
public function testToArray($tags, $timestamp, $type, $target)
{
$timePoint = new TimePoint($tags, $timestamp, $type, $target);
$data = $timePoint->toArray();

$this->assertEquals($timePoint->getTimestamp(), $data['ts']);
$this->assertEquals($timePoint->getTarget(), $data['target']);
$this->assertEquals($timePoint->getTags(), $data['tags']);
$this->assertEquals($timePoint->getType(), $data['type']);
}

/**
* @dataProvider testSerializeProvider
* @param $tags
* @param $timestamp
* @param $type
* @param $target
*/
public function testFromArray($tags, $timestamp, $type, $target)
{
$timePoint = new TimePoint();
$timePoint->fromArray([
'ts' => $timestamp,
'type' => $type,
'target' => $target,
'tags' => $tags,
]);

$expected = [
'ts' => $timestamp,
'type' => $type,
'target' => $target,
'tags' => (array)$tags,
];

$this->assertEquals($expected['ts'], $timePoint->getTimestamp());
$this->assertEquals($expected['target'], $timePoint->getTarget());
$this->assertEquals($expected['tags'], $timePoint->getTags());
$this->assertEquals($expected['type'], $timePoint->getType());
}

/**
* @dataProvider testSerializeProvider
* @param $tags
Expand Down Expand Up @@ -322,4 +389,4 @@ public function testSortProvider()
]
];
}
}
}
Loading

0 comments on commit 48e08b6

Please sign in to comment.