mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
create first tests on history file
This commit is contained in:
parent
e5f67e32c3
commit
29ee79c645
@ -84,7 +84,7 @@ class Person {
|
||||
$opening = new \DateTime();
|
||||
}
|
||||
|
||||
$this->open($opening);
|
||||
$this->open(new PersonHistoryFile($opening));
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,182 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Chill\PersonBundle\Entity\PersonHistoryFile;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
class HistoryControllerTest extends WebTestCase
|
||||
{
|
||||
public function testClosingIsAfterOpeningConsistency()
|
||||
{
|
||||
$datetime1 = new \DateTime('now');
|
||||
|
||||
$history = new PersonHistoryFile($datetime1);
|
||||
|
||||
|
||||
$datetime2 = new \DateTime('tomorrow');
|
||||
|
||||
$history->setDateClosing($datetime2);
|
||||
|
||||
|
||||
$r = $history->isClosingAfterOpening();
|
||||
|
||||
$this->assertTrue($r);
|
||||
}
|
||||
|
||||
public function testClosingIsBeforeOpeningConsistency() {
|
||||
$datetime1 = new \DateTime('tomorrow');
|
||||
|
||||
|
||||
$history = new PersonHistoryFile($datetime1);
|
||||
|
||||
|
||||
$datetime2 = new \DateTime('now');
|
||||
|
||||
$history->setDateClosing($datetime2);
|
||||
|
||||
$this->assertFalse($history->isClosingAfterOpening());
|
||||
}
|
||||
|
||||
public function testClosingEqualOpening() {
|
||||
$datetime = new \DateTime('now');
|
||||
|
||||
$history = new PersonHistoryFile($datetime);
|
||||
$history->setDateClosing($datetime);
|
||||
|
||||
$this->assertTrue($history->isClosingAfterOpening());
|
||||
}
|
||||
|
||||
public function testIsOpen() {
|
||||
$history = new PersonHistoryFile(new \DateTime());
|
||||
|
||||
$this->assertTrue($history->isOpen());
|
||||
}
|
||||
|
||||
public function testIsClosed() {
|
||||
$history = new PersonHistoryFile(new \DateTime());
|
||||
|
||||
$history->setDateClosing(new \DateTime('tomorrow'));
|
||||
|
||||
$this->assertFalse($history->isOpen());
|
||||
}
|
||||
|
||||
public function testHistoryOrderWithUnorderedHistory() {
|
||||
$d = new \DateTime(); $d->setDate(2013, 2, 1);
|
||||
$p = new Person($d);
|
||||
|
||||
$e = new \DateTime(); $e->setDate(2013,3,1);
|
||||
$p->close($e, null);
|
||||
|
||||
$f = new \DateTime(); $f->setDate(2013, 1, 1);
|
||||
$p->open($f);
|
||||
|
||||
$g = new \DateTime(); $g->setDate(2013, 4, 1);
|
||||
$p->close($g, null);
|
||||
|
||||
$r = $p->getHistoriesOrdered();
|
||||
|
||||
$date = $r[0]->getDateOpening()->format('Y-m-d');
|
||||
|
||||
|
||||
$this->assertEquals($date, '2013-01-01');
|
||||
}
|
||||
|
||||
|
||||
public function testHistoryOrderSameDateOpening() {
|
||||
$d = new \DateTime(); $d->setDate(2013, 2, 1);
|
||||
$p = new Person($d);
|
||||
|
||||
$e = new \DateTime(); $e->setDate(2013, 3, 1);
|
||||
$p->close($e, null);
|
||||
|
||||
$f = new \DateTime(); $f->setDate(2013, 2, 1);
|
||||
$p->open($f);
|
||||
|
||||
$g = new \DateTime(); $g->setDate(2013, 4, 1);
|
||||
$p->close($g, null);
|
||||
|
||||
$r = $p->getHistoriesOrdered();
|
||||
|
||||
$date = $r[0]->getDateClosing()->format('Y-m-d');
|
||||
|
||||
|
||||
$this->assertEquals($date, '2013-03-01');
|
||||
}
|
||||
|
||||
public function testDateCoveringWithCoveringHistory() {
|
||||
$d = new \DateTime(); $d->setDate(2013, 2, 1);
|
||||
$p = new Person($d);
|
||||
|
||||
$e = new \DateTime(); $e->setDate(2013,3,1);
|
||||
$p->close($e, null);
|
||||
|
||||
$f = new \DateTime(); $f->setDate(2013, 1, 1);
|
||||
$p->open($f);
|
||||
|
||||
$g = new \DateTime(); $g->setDate(2013, 4, 1);
|
||||
$p->close($g, null);
|
||||
|
||||
$r = $p->checkHistoryIsNotCovering();
|
||||
|
||||
$this->assertEquals($r['result'], Person::ERROR_OPENING_IS_INSIDE_CLOSING);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testNotOpenAFileReOpenedLater() {
|
||||
$d = new \DateTime(); $d->setDate(2013, 2, 1);
|
||||
$p = new Person($d);
|
||||
|
||||
$e = new \DateTime(); $e->setDate(2013, 3, 1);
|
||||
$p->close($e, null);
|
||||
|
||||
$f = new \DateTime(); $f->setDate(2013, 1, 1);
|
||||
$p->open($f);
|
||||
|
||||
|
||||
|
||||
$r = $p->checkHistoryIsNotCovering();
|
||||
|
||||
var_dump($r);
|
||||
|
||||
$this->assertEquals($r['result'], Person::ERROR_OPENING_NOT_CLOSED_IS_BEFORE_NEW_LINE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function testOrder() {
|
||||
$d = new \DateTime(); $d->setDate(2013, 2, 1);
|
||||
$g = new \DateTime(); $g->setDate(2013, 4, 1);
|
||||
$f = new \DateTime(); $f->setDate(2013, 1, 1);
|
||||
$e = new \DateTime(); $e->setDate(2013,3,1);
|
||||
|
||||
$a = array($d, $g, $f, $e);
|
||||
|
||||
|
||||
usort($a, function($a, $b) {
|
||||
if ($a === $b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($a < $b) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$date = $a[0]->format('Y-m-d');
|
||||
|
||||
$this->assertEquals($date, '2013-01-01');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -6,11 +6,9 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class PersonControllerTest extends WebTestCase
|
||||
{
|
||||
public function testSee()
|
||||
public function testFoo()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$crawler = $client->request('GET', '/see');
|
||||
}
|
||||
|
||||
}
|
||||
|
103
Tests/Entity/HistoryFileTest.php
Normal file
103
Tests/Entity/HistoryFileTest.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Entity;
|
||||
|
||||
use Chill\PersonBundle\Entity\PersonHistoryFile;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
class HistoryFileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testClosingIsAfterOpeningConsistency()
|
||||
{
|
||||
$datetime1 = new \DateTime('now');
|
||||
|
||||
$history = new PersonHistoryFile($datetime1);
|
||||
|
||||
|
||||
$datetime2 = new \DateTime('tomorrow');
|
||||
|
||||
$history->setDateClosing($datetime2);
|
||||
|
||||
|
||||
$r = $history->isClosingAfterOpening();
|
||||
|
||||
$this->assertTrue($r);
|
||||
}
|
||||
|
||||
public function testClosingIsBeforeOpeningConsistency() {
|
||||
$datetime1 = new \DateTime('tomorrow');
|
||||
|
||||
|
||||
$history = new PersonHistoryFile($datetime1);
|
||||
|
||||
|
||||
$datetime2 = new \DateTime('now');
|
||||
|
||||
$history->setDateClosing($datetime2);
|
||||
|
||||
$this->assertFalse($history->isClosingAfterOpening());
|
||||
}
|
||||
|
||||
public function testClosingEqualOpening() {
|
||||
$datetime = new \DateTime('now');
|
||||
|
||||
$history = new PersonHistoryFile($datetime);
|
||||
$history->setDateClosing($datetime);
|
||||
|
||||
$this->assertTrue($history->isClosingAfterOpening());
|
||||
}
|
||||
|
||||
public function testIsOpen() {
|
||||
$history = new PersonHistoryFile(new \DateTime());
|
||||
|
||||
$this->assertTrue($history->isOpen());
|
||||
}
|
||||
|
||||
public function testIsClosed() {
|
||||
$history = new PersonHistoryFile(new \DateTime());
|
||||
|
||||
$history->setDateClosing(new \DateTime('tomorrow'));
|
||||
|
||||
$this->assertFalse($history->isOpen());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This test seems only to test ordering datetime... Maybe delete ?
|
||||
*/
|
||||
public function testOrder() {
|
||||
$d = new \DateTime(); $d->setDate(2013, 2, 1);
|
||||
$g = new \DateTime(); $g->setDate(2013, 4, 1);
|
||||
$f = new \DateTime(); $f->setDate(2013, 1, 1);
|
||||
$e = new \DateTime(); $e->setDate(2013,3,1);
|
||||
|
||||
$a = array($d, $g, $f, $e);
|
||||
|
||||
|
||||
usort($a, function($a, $b) {
|
||||
if ($a === $b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($a < $b) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$date = $a[0]->format('Y-m-d');
|
||||
|
||||
$this->assertEquals($date, '2013-01-01');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
152
Tests/Entity/PersonTest.php
Normal file
152
Tests/Entity/PersonTest.php
Normal file
@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2014 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Entity;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\PersonHistoryFile;
|
||||
|
||||
/**
|
||||
* Unit tests on person
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class PersonTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetCurrentHistory()
|
||||
{
|
||||
$d = new \DateTime('yesterday');
|
||||
$p = new Person($d);
|
||||
|
||||
$history = $p->getCurrentHistory();
|
||||
|
||||
$this->assertInstanceOf('Chill\PersonBundle\Entity\PersonHistoryFile', $history);
|
||||
$this->assertTrue($history->isOpen());
|
||||
$this->assertEquals($d, $history->getDateOpening());
|
||||
|
||||
//close and test
|
||||
$history->setDateClosing(new \DateTime('tomorrow'));
|
||||
|
||||
$shouldBeNull = $p->getCurrentHistory();
|
||||
$this->assertNull($shouldBeNull);
|
||||
|
||||
}
|
||||
|
||||
public function testHistoryOrderWithUnorderedHistory() {
|
||||
$d = new \DateTime();
|
||||
$d->setDate(2013, 2, 1);
|
||||
$p = new Person($d);
|
||||
|
||||
$e = new \DateTime();
|
||||
$e->setDate(2013, 3, 1);
|
||||
$history = $p->getCurrentHistory()->setDateClosing($e);
|
||||
$p->close($history);
|
||||
|
||||
$f = new \DateTime();
|
||||
$f->setDate(2013, 1, 1);
|
||||
$p->open(new PersonHistoryFile($f));
|
||||
|
||||
$g = new \DateTime();
|
||||
$g->setDate(2013, 4, 1);
|
||||
$history = $p->getCurrentHistory()->setDateClosing($g);
|
||||
$p->close($history);
|
||||
|
||||
$r = $p->getHistoriesOrdered();
|
||||
|
||||
$date = $r[0]->getDateOpening()->format('Y-m-d');
|
||||
|
||||
|
||||
$this->assertEquals($date, '2013-01-01');
|
||||
}
|
||||
|
||||
|
||||
public function testHistoryOrderSameDateOpening() {
|
||||
$d = new \DateTime();
|
||||
$d->setDate(2013, 2, 1);
|
||||
$p = new Person($d);
|
||||
|
||||
$e = new \DateTime();
|
||||
$e->setDate(2013, 3, 1);
|
||||
$history = $p->getCurrentHistory()->setDateClosing($e);
|
||||
$p->close($history);
|
||||
|
||||
$f = new \DateTime();
|
||||
$f->setDate(2013, 2, 1);
|
||||
$p->open(new PersonHistoryFile($f));
|
||||
|
||||
$g = new \DateTime();
|
||||
$g->setDate(2013, 4, 1);
|
||||
$history = $p->getCurrentHistory()->setDateClosing($g);
|
||||
$p->close($history);
|
||||
|
||||
$r = $p->getHistoriesOrdered();
|
||||
|
||||
$date = $r[0]->getDateClosing()->format('Y-m-d');
|
||||
|
||||
|
||||
$this->assertEquals($date, '2013-03-01');
|
||||
}
|
||||
|
||||
public function testDateCoveringWithCoveringHistory() {
|
||||
$d = new \DateTime();
|
||||
$d->setDate(2013, 2, 1);
|
||||
$p = new Person($d);
|
||||
|
||||
$e = new \DateTime();
|
||||
$e->setDate(2013, 3, 1);
|
||||
$history = $p->getCurrentHistory()->setDateClosing($e);
|
||||
$p->close($history);
|
||||
|
||||
$f = new \DateTime();
|
||||
$f->setDate(2013, 1, 1);
|
||||
$p->open(new PersonHistoryFile($f));
|
||||
|
||||
$g = new \DateTime();
|
||||
$g->setDate(2013, 4, 1);
|
||||
$history = $p->getCurrentHistory()->setDateClosing($g);
|
||||
$p->close($history);
|
||||
|
||||
$r = $p->checkHistoryIsNotCovering();
|
||||
|
||||
$this->assertEquals($r['result'], Person::ERROR_OPENING_IS_INSIDE_CLOSING);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testNotOpenAFileReOpenedLater() {
|
||||
$d = new \DateTime();
|
||||
$d->setDate(2013, 2, 1);
|
||||
$p = new Person($d);
|
||||
|
||||
$e = new \DateTime();
|
||||
$e->setDate(2013, 3, 1);
|
||||
$history = $p->getCurrentHistory()->setDateClosing($e);
|
||||
$p->close($history);
|
||||
|
||||
$f = new \DateTime();
|
||||
$f->setDate(2013, 1, 1);
|
||||
$p->open(new PersonHistoryFile($f));
|
||||
|
||||
|
||||
$r = $p->checkHistoryIsNotCovering();
|
||||
|
||||
$this->assertEquals($r['result'], Person::ERROR_OPENING_NOT_CLOSED_IS_BEFORE_NEW_LINE);
|
||||
}
|
||||
}
|
8
Tests/bootstrap.php
Normal file
8
Tests/bootstrap.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
if (!is_file($autoloadFile = __DIR__.'/../vendor/autoload.php')) {
|
||||
throw new \LogicException('Could not find autoload.php in vendor/. Did you run "composer install --dev"?');
|
||||
}
|
||||
|
||||
require $autoloadFile;
|
||||
|
23
phpunit.xml.dist
Normal file
23
phpunit.xml.dist
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit bootstrap="./Tests/bootstrap.php" colors="true">
|
||||
<!-- the file "./Tests/boostrap.php" will be created on the next step -->
|
||||
<testsuites>
|
||||
<testsuite name="ChillPersonBundle test suite">
|
||||
<directory suffix="Test.php">./Tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./</directory>
|
||||
<exclude>
|
||||
<directory>./Resources</directory>
|
||||
<directory>./Tests</directory>
|
||||
<directory>./vendor</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<php>
|
||||
<server name="KERNEL_DIR" value="/Tests/Fixtures/App/app/" />
|
||||
</php>
|
||||
</phpunit>
|
Loading…
x
Reference in New Issue
Block a user