1<?php 2 3/* 4 * $Id$ 5 * 6 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 7 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 8 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 9 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 10 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 11 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 12 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 13 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 16 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 17 * 18 * This software consists of voluntary contributions made by many individuals 19 * and is licensed under the LGPL. For more information, see 20 * <http://www.doctrine-project.org>. 21 */ 22 23/** 24 * Doctrine_Ticket_1116_TestCase 25 * 26 * @package Doctrine 27 * @author Konsta Vesterinen <kvesteri@cc.hut.fi> 28 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL 29 * @category Object Relational Mapping 30 * @link www.doctrine-project.org 31 * @since 1.0 32 * @version $Revision$ 33 */ 34class Doctrine_Ticket_1116_TestCase extends Doctrine_UnitTestCase 35{ 36 public function setUp() 37 { 38 //switch to a real db to trigger the Exception 39 $this->dbh = new Doctrine_Adapter_Mock('mysql'); 40 //$this->dbh = new PDO("mysql:host=localhost;dbname=testing", 'root', 'password'); 41 42 $this->conn = Doctrine_Manager::getInstance()->openConnection($this->dbh); 43 $this->conn->export->exportClasses(array('Ticket_1116_User')); 44 } 45 46 47 public function testTicket() 48 { 49 Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true); 50 $q = new Doctrine_Query(); 51 $q->select('s.*') 52 ->from('Ticket_1116_User s') 53 ->where('s.username = ?', array('test')); 54 55 // to see the error switch dbh to a real db, the next line will trigger the error 56 $test = $q->fetchOne(); //will only fail with "real" mysql 57 $this->assertFalse($test); 58 59 $sql = $q->getSqlQuery(); // just getSql()?!?! and it works ? the params are ok after this call 60 $params = $q->getFlattenedParams(); 61 $this->assertEqual(count($params), 1); // now we have array('test',null) very strange ..... 62 63 $this->assertEqual($sql, "SELECT u.id AS u__id, u.username AS u__username, u.deleted_at AS u__deleted_at FROM user u WHERE (u.username = ? AND (u.deleted_at IS NULL))"); 64 $this->assertEqual($params, array('test')); 65 66 //now also this works! (always works witch mock only fails with mysql) 67 $test = $q->fetchOne(); 68 $this->assertFalse($test); 69 Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, false); 70 } 71} 72 73 74class Ticket_1116_User extends Doctrine_Record 75{ 76 public function setTableDefinition() 77 { 78 $this->setTableName('user'); 79 $this->hasColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true)); 80 $this->hasColumn('username', 'string', 255); 81 } 82 83 84 public function setUp() 85 { 86 parent::setUp(); 87 $softdelete0 = new Doctrine_Template_SoftDelete(); 88 $this->actAs($softdelete0); 89 } 90}