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

Fixed tests #139

Merged
merged 4 commits into from
Mar 7, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6

install:
- composer self-update && composer install

notifications:
email: false

script: vendor/bin/phpunit -c tests/phpunit.dist.xml
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"name": "beberlei/DoctrineExtensions",
"require": {
"doctrine/orm": "*"
"php": ">=5.3.2"
},
"require-dev": {
"doctrine/orm": "<2.2",
"phpunit/phpunit": "~4.5"
},
"autoload": {
"psr-0": {"DoctrineExtensions" : "lib/"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testCountQuery_MixedResultsWithName()
$limitQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('DoctrineExtensions\Paginate\LimitSubqueryWalker'));

$this->assertEquals(
"SELECT DISTINCT a0_.id AS id0 FROM Author a0_", $limitQuery->getSql()
"SELECT DISTINCT a0_.id AS id0, sum(a0_.name) AS sclr1 FROM Author a0_", $limitQuery->getSql()
);
}

Expand Down
10 changes: 5 additions & 5 deletions tests/DoctrineExtensions/Query/MysqlTrigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Doctrine\ORM\Query\Parser;

require_once __DIR__ . '/../../Entities/BlogPost.php';

class MysqlTrigTest extends \PHPUnit_Framework_TestCase
{

Expand All @@ -14,12 +16,10 @@ public function setUp()
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
$config->setProxyDir($GLOBALS['doctrine2-proxies-path']);
$config->setProxyNamespace($GLOBALS['doctrine2-proxies-namespace']);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('DoctrineExtensions\PHPUnit\Proxies');
$config->setAutoGenerateProxyClasses(true);

$driver = $config->newDefaultAnnotationDriver($GLOBALS['doctrine2-entities-path']);
$config->setMetadataDriverImpl($driver);
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(__DIR__ . '/../../Entities'));

$conn = array(
'driver' => 'pdo_sqlite',
Expand Down
43 changes: 24 additions & 19 deletions tests/DoctrineExtensions/Query/MysqlUdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace DoctrineExtensions\Query;
use Doctrine\ORM\Query\Parser;

require_once __DIR__ . '/../../Entities/BlogPost.php';

class MysqlUdfTest extends \PHPUnit_Framework_TestCase
{
public $entityManager = null;
Expand All @@ -12,12 +14,10 @@ public function setUp()
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
$config->setProxyDir($GLOBALS['doctrine2-proxies-path']);
$config->setProxyNamespace($GLOBALS['doctrine2-proxies-namespace']);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('DoctrineExtensions\PHPUnit\Proxies');
$config->setAutoGenerateProxyClasses(true);

$driver = $config->newDefaultAnnotationDriver($GLOBALS['doctrine2-entities-path']);
$config->setMetadataDriverImpl($driver);
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(__DIR__ . '/../../Entities'));

$conn = array(
'driver' => 'pdo_sqlite',
Expand All @@ -26,8 +26,8 @@ public function setUp()

$config->addCustomNumericFunction('DATEDIFF', 'DoctrineExtensions\Query\Mysql\DateDiff');
$config->addCustomDatetimeFunction('DATE_ADD', 'DoctrineExtensions\Query\Mysql\DateAdd');
$config->addCustomStringFunction('STR_TO_DATE', 'DoctrineExtensions\Query\MySql\StrToDate');
$config->addCustomStringFunction('FIND_IN_SET', 'DoctrineExtensions\Query\MySql\FindInSet');
$config->addCustomStringFunction('STR_TO_DATE', 'DoctrineExtensions\Query\Mysql\StrToDate');
$config->addCustomStringFunction('FIND_IN_SET', 'DoctrineExtensions\Query\Mysql\FindInSet');
$this->entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);

}
Expand All @@ -42,43 +42,48 @@ public function testDateDiff()

}

/**
* @expectedException Doctrine\ORM\Query\QueryException
*/
public function testDateAdd()
{
$dql = "SELECT p FROM Entities\BlogPost p WHERE DATE_ADD(CURRENT_TIME(), INTERVAL 4 MONTH) < 7";
$q = $this->entityManager->createQuery($dql);

$sql = "SELECT b0_.id AS id0, b0_.created AS created1, b0_.longitude AS longitude2, b0_.latitude AS latitude3 FROM BlogPost b0_ WHERE DATE_ADD(CURRENT_TIME, INTERVAL 4 MONTH) < 7";
$this->assertEquals($sql, $q->getSql());

$this->assertEquals($sql, $q->getSql());
}

/**
* @expectedException Doctrine\ORM\Query\QueryException
*/
public function testDateAdd2()
{
$dql = "SELECT p FROM Entities\BlogPost p WHERE DATE_ADD(CURRENT_TIME(), p.created) < 7";
$q = $this->entityManager->createQuery($dql);

$this->setExpectedException('Doctrine\ORM\Query\QueryException');

$q->getSql();
$sql = '';

$this->assertEquals($sql, $q->getSql());
}

public function testStrToDate()
{
$dql = "SELECT p FROM DoctrineExtensions\Query\BlogPost p WHERE STR_TO_DATE(p.created, :dateFormat) < :currentTime";
$q = $this->entityManager->createQuery($dql);
$q->setParameter('dateFormat', '%Y-%m-%d %h:%i %p');
$q->setParameter('currentTime', date('Y-m-d H:i:s'));
var_dump($q->getSql());

$this->assertEquals('SELECT b0_.id AS id0, b0_.testSet AS testSet1, b0_.created AS created2 FROM BlogPost b0_ WHERE STR_TO_DATE(b0_.created, ?) < ?', $q->getSql());
}

public function testFindInSet()
{
$dql = "SELECT p FROM DoctrineExtensions\Query\BlogPost p WHERE FIND_IN_SET(p.id, p.testSet) != 0";
$q = $this->entityManager->createQuery($dql);

var_dump($q->getSql());
$this->assertEquals('SELECT b0_.id AS id0, b0_.testSet AS testSet1, b0_.created AS created2 FROM BlogPost b0_ WHERE FIND_IN_SET(b0_.id, b0_.testSet) <> 0', $q->getSql());
}
}

Expand All @@ -89,14 +94,14 @@ class BlogPost
{
/** @Id @Column(type="string") @GeneratedValue */
public $id;

/**
* @Column(type="String")
*/
public $testSet;

/**
* @Column(type="DateTime")
*/
public $created;
}
}
11 changes: 1 addition & 10 deletions tests/phpunit.dist.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="../vendor/autoload.php"
colors="true"
>
<phpunit bootstrap="../vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="AllTests">
<directory>DoctrineExtensions/LargeCollections</directory>
<directory>DoctrineExtensions/Paginate</directory>
<directory>DoctrineExtensions/Query</directory>
</testsuite>
</testsuites>
<php>
<var name="doctrine2-path" value="" />
<var name="doctrine2-entities-path" value="" />
<var name="doctrine2-proxies-path" value="" />
<var name="doctrine2-proxies-namespace" value="" />
</php>
<filter>
<blacklist>
<directory suffix=".php"></directory>
Expand Down