PHP Classes

File: tests/simple-tests/SimpleTest.php

Recommend this page to a friend!
  Classes of Maik Greubel  >  Caribu ORM  >  tests/simple-tests/SimpleTest.php  >  Download  
File: tests/simple-tests/SimpleTest.php
Role: Unit test script
Content type: text/plain
Description: Simple unit test
Class: Caribu ORM
Map objects to databases records using annotations
Author: By
Last change: Strong type and documentation fixes
Date: 3 years ago
Size: 3,831 bytes
 

Contents

Class file image Download
<?php
namespace Nkey\Caribu\Tests;

require_once
dirname(__FILE__).'/../AbstractDatabaseTestCase.php';
require_once
dirname(__FILE__).'/../Model/MockedModel.php';
require_once
dirname(__FILE__).'/../Model/GuestBookModel.php';
require_once
dirname(__FILE__).'/../Model/AnnotatedGuestBookModel.php';

use
Nkey\Caribu\Tests\Model\MockedModel;
use
Nkey\Caribu\Tests\Model\GuestBookModel;
use
Nkey\Caribu\Tests\Model\AnnotatedGuestBookModel;

use
Nkey\Caribu\Orm\Orm;

/**
 * Simple test cases
 *
 * This class is part of Caribu package
 *
 * @author Maik Greubel <greubel@nkey.de>
 */
class SimpleTest extends AbstractDatabaseTestCase
{
    public function
__construct()
    {
       
parent::__construct();
       
       
$this->options = array(
           
'type' => 'sqlite',
           
'file' => ':memory:'
       
);

       
$this->flatDataSetFile = dirname(__FILE__).'/../_files/guestbook-seed.xml';
    }

   
/**
     * (non-PHPdoc)
     * @see \PHPUnit\DbUnit\TestCase::setUp()
     */
   
protected function setUp()
    {
       
Orm::passivate();

       
$connection = $this->getConnection()->getConnection();
       
$connection->beginTransaction();
       
$connection->query("CREATE TABLE guestbook (id INTEGER PRIMARY KEY AUTOINCREMENT, content TEXT, user TEXT, created TEXT)");
       
$connection->commit();

       
parent::setUp();
    }

   
/**
     * (non-PHPdoc)
     * @see \PHPUnit\DbUnit\TestCase::tearDown()
     */
   
protected function tearDown()
    {
       
$connection = $this->getConnection()->getConnection();
       
$connection->beginTransaction();
       
$connection->query("DROP TABLE guestbook");
       
$connection->commit();

       
parent::tearDown();
    }

   
/**
     * Test simple
     */
   
public function testSimple()
    {
       
$model = new MockedModel();
       
$this->assertFalse($model->getConnection() == null);
    }

   
/**
     * Test fetching
     */
   
public function testFetching()
    {
       
$entity = GuestBookModel::get(1);
       
$this->assertFalse(is_null($entity));
       
$this->assertEquals("joe", $entity->getUser());
    }

   
/**
     * Test annotated fetching
     */
   
public function testAnnotated()
    {
       
$entity = AnnotatedGuestBookModel::get(1);
       
$this->assertFalse(is_null($entity));
       
$this->assertEquals(1, $entity->getGid());
       
$this->assertEquals("joe", $entity->getUser());
    }

   
/**
     * Test finding
     */
   
public function testFind()
    {
       
$entity = AnnotatedGuestBookModel::find(array('user' => 'joe'), 'id ASC', 1);
       
$this->assertFalse(is_null($entity));
       
$this->assertEquals(1, $entity->getGid());
       
$this->assertEquals("joe", $entity->getUser());
    }

   
/**
     * Test finding via like keyword
     */
   
public function testLikeFind()
    {
       
$entity = AnnotatedGuestBookModel::find(array('user' => 'LIKE jo%'), 'id ASC', 1);
       
$this->assertFalse(is_null($entity));
       
$this->assertEquals(1, $entity->getGid());
       
$this->assertEquals("joe", $entity->getUser());
    }

   
/**
     * Test the finding via OR condition instead of default AND
     */
   
public function testOrFind()
    {
       
$entities = AnnotatedGuestBookModel::find(array('user' => 'joe', 'OR user' => 'bob'));
       
$this->assertEquals(3, count($entities));
    }

   
/**
     * Test the finding via OR condition instead of default AND using LIKE modifier
     */
   
public function testOrLikeFind()
    {
       
$entities = AnnotatedGuestBookModel::find(array('user' => 'LIKE jo%', 'OR user' => 'LIKE bo%'));
       
$this->assertEquals(3, count($entities));
    }

    public function
testBetween()
    {
       
$entities = AnnotatedGuestBookModel::find(array('gid' => 'BETWEEN 1 AND 3'));
       
$this->assertEquals(3, count($entities));
    }
}


For more information send a message to info at phpclasses dot org.