Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ttl mode on windows #535

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions common/persistence/class.PhpFileDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,11 @@ private function writeFile($id, $value, $preWriteValueProcessor = null)
public function get($id)
{
$entry = $this->readFile($id);
if ($entry != false && $this->isTtlMode()) {
$entry = (is_null($entry[static::ENTRY_EXPIRATION]) || $entry[static::ENTRY_EXPIRATION] > $this->getTime())

if ($entry !== false && $this->isTtlMode()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($entry !== false && $this->isTtlMode()) {
if ($entry !== false && $this->isTtlMode()) {

@jbout Please, confirm that I can change this behavior: before it worked like this: when file has return null - driver return null as a result, but now in such situation it returns 'false'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ttlMode is true, no file should ever return "null", it should still always return an array with the expiry and the value

$entry = isset($entry)
&& array_key_exists(static::ENTRY_EXPIRATION, $entry)
&& (is_null($entry[static::ENTRY_EXPIRATION]) || $entry[static::ENTRY_EXPIRATION] > $this->getTime())
? $entry[static::ENTRY_VALUE]
: false
;
Expand Down Expand Up @@ -352,7 +355,7 @@ public function purge()
}

/**
* Map the provided key to a relativ path
* Map the provided key to a relative path
*
* @param string $key
* @return string
Expand Down
2 changes: 1 addition & 1 deletion manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'label' => 'Generis Core',
'description' => 'Core extension, provide the low level framework and an API to manage ontologies',
'license' => 'GPL-2.0',
'version' => '7.9.10',
'version' => '7.9.11',
'author' => 'Open Assessment Technologies, CRP Henri Tudor',
'requires' => array(),
'models' => array(
Expand Down
2 changes: 1 addition & 1 deletion scripts/update/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,6 @@ public function update($initialVersion) {
$this->setVersion('7.2.0');
}

$this->skip('7.2.0', '7.9.10');
$this->skip('7.2.0', '7.9.11');
}
}
84 changes: 84 additions & 0 deletions test/integration/common/PhpFileDriverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?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) 2018 (original work) Open Assessment Technologies SA;
*
* @author Alexander Zagovorichev <[email protected]>
*/

class PhpFileDriverTest extends PHPUnit_Framework_TestCase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a namespace to prevent collisions, and this test should work even if tao is not installed, could you consider it a unit test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I can consider it is a unit test and this test will work even if tao is not installed. You don't like that I read real files?

{
/**
* @var common_persistence_PhpFileDriver
*/
private $driver;

protected function setUp()
{
$this->driver = new common_persistence_PhpFileDriver();
}

public function testGetFalse()
{
self::assertFalse($this->driver->get(false));
self::assertFalse($this->driver->get(null));
self::assertFalse($this->driver->get(''));
self::assertFalse($this->driver->get('not existent'));
}

public function testGet()
{
$this->driver->connect(false, [
'dir' => __DIR__ . '/samples/',
'humanReadable' => true,
]);
self::assertEquals('content is here', $this->driver->get('test'));
}

public function testTtlMode()
{
$this->driver->connect(false, [
'dir' => __DIR__ . '/samples/',
'humanReadable' => true,
'ttlMode' => true,
]);
self::assertEquals('Sword', $this->driver->get('testTtl'));
}

public function ttlFalseDataProvider ()
{
return [
['testTtlEmpty'],
['testTtlNull'],
['testTtlNoExpires'],
['testTtlExpired'],
];
}

/**
* @dataProvider ttlFalseDataProvider
*/
public function testFalseTtl($id)
{
$this->driver->connect(false, [
'dir' => __DIR__ . '/samples/',
'humanReadable' => true,
'ttlMode' => true,
]);
self::assertFalse($this->driver->get($id));
}

}
2 changes: 2 additions & 0 deletions test/integration/common/samples/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
return 'content is here';
5 changes: 5 additions & 0 deletions test/integration/common/samples/testTtl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
return [
'expiresAt' => time() + 1000,
'value' => 'Sword',
];
2 changes: 2 additions & 0 deletions test/integration/common/samples/testTtlEmpty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
return [];
5 changes: 5 additions & 0 deletions test/integration/common/samples/testTtlExpired.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
return [
'expiresAt' => time() - 1000,
'value' => 'Sword',
];
4 changes: 4 additions & 0 deletions test/integration/common/samples/testTtlNoExpires.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
return [
'value' => 'Sword',
];
2 changes: 2 additions & 0 deletions test/integration/common/samples/testTtlNull.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
return null;