PHP Classes

File: tests/eMapper/SQLite/Callback/IndexCallbackTest.php

Recommend this page to a friend!
  Packages of Emmanuel Antico   eMapper   tests/eMapper/SQLite/Callback/IndexCallbackTest.php   Download  
File: tests/eMapper/SQLite/Callback/IndexCallbackTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: eMapper
Database abstraction layer that maps data types
Author: By
Last change: Modified: Callback tests.
Date: 12 years ago
Size: 1,382 bytes
 

 

Contents

Class file image Download
<?php
namespace eMapper\SQLite\Callback;

use eMapper\SQLite\SQLiteConfig;
use eMapper\Callback\AbstractIndexCallbackTest;

/**
 * Index callback tests
 * @author emaphp
 * @group sqlite
 * @group callback
 */
class IndexCallbackTest extends AbstractIndexCallbackTest {
    use SQLiteConfig;
    
    public function testClosureIndex() {
        $list = $this->mapper->index_callback(function ($user) {
            $date = \DateTime::createFromFormat('Y-m-d', $user->birth_date);
            return intval($date->format('Y'));
        })
        ->type('obj[]')->query("SELECT * FROM users");
    
        $this->assertInternalType('array', $list);
        $this->assertCount(5, $list);
    
        //assert indexes
        $this->assertArrayHasKey(1987, $list);
        $this->assertArrayHasKey(1976, $list);
        $this->assertArrayHasKey(1967, $list);
        $this->assertArrayHasKey(1980, $list);
        $this->assertArrayHasKey(1977, $list);
    
        //assert values
        $this->assertInstanceOf('stdClass', $list[1987]);
        $this->assertInstanceOf('stdClass', $list[1976]);
        $this->assertInstanceOf('stdClass', $list[1967]);
        $this->assertInstanceOf('stdClass', $list[1980]);
        $this->assertInstanceOf('stdClass', $list[1977]);
    
        $this->assertEquals(1, $list[1987]->user_id);
        $this->assertEquals(2, $list[1976]->user_id);
        $this->assertEquals(3, $list[1967]->user_id);
        $this->assertEquals(4, $list[1980]->user_id);
        $this->assertEquals(5, $list[1977]->user_id);
    }
}
?>