PHP Classes

File: tests/failure-tests/DuplicateIdTest.php

Recommend this page to a friend!
  Classes of Maik Greubel   Caribu ORM   tests/failure-tests/DuplicateIdTest.php   Download  
File: tests/failure-tests/DuplicateIdTest.php
Role: Unit test script
Content type: text/plain
Description: Test duplicate id behaviour
Class: Caribu ORM
Map objects to databases records using annotations
Author: By
Last change: Strong type and documentation fixes
Date: 7 years ago
Size: 1,863 bytes
 

Contents

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

require_once
dirname(__FILE__).'/../AbstractDatabaseTestCase.php';
require_once
dirname(__FILE__).'/../Model/User.php';

use
Nkey\Caribu\Tests\Model\User;

use
Nkey\Caribu\Orm\Orm;

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

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

       
$connection = $this->getConnection()->getConnection();
       
$connection->beginTransaction();
       
$connection->exec("CREATE TABLE user (uid INTEGER, name TEXT, email TEXT)");
       
$connection->commit();

       
parent::setUp();
    }

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

       
parent::tearDown();
    }

   
/**
     * @expectedException Nkey\Caribu\Orm\OrmException
     * @expectedExceptionMessage More than one entity found (expected exactly one)
     */
   
public function testDuplicateId()
    {
       
$user = new User();
       
$user->setId(1);
       
$user->setName('joe');
       
$user->setEmail('joe@test.tld');
       
$user->persist();

       
$user = new User();
       
$user->setId(1);
       
$user->setName('jane');
       
$user->setEmail('jane@test.tld');
       
$user->persist();

       
User::get(1);
    }

}