Skip to content
This repository
tree: c79ad79cb5
Fetching contributors…

Cannot retrieve contributors at this time

file 47 lines (42 sloc) 1.532 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
<?php
require_once dirname(__FILE__).'/../src/Morph/Utils.php';
/**
* @package Morph
*/
class TestUtils extends PHPUnit_Framework_TestCase
{

    public function testCollectionName()
    {
        $object = $this->getMock('Morph_Object', array(), array(), 'user_Profile');
        $collectionName = Morph_Utils::collectionName($object);
        $this->assertEquals('user.Profile', $collectionName);
    }

    public function testNamespacedCollectionName()
    {
        if (version_compare(PHP_VERSION, '5.3.0') === -1) {
            $this->markTestSkipped("Skipped for PHP Versions lower than 5.3.0");
            return;
        }
        $mockMorphObject = $this->getMock('Morph_Object');
        require dirname(__FILE__) . '/namespaced_stub.php';
        $object = new user\Profile();
        $collectionName = Morph_Utils::collectionName($object);
        $this->assertEquals('user.Profile', $collectionName);
    }

    public function testObjectReference()
    {
        $object = $this->getMock('Morph_Object', array('id', 'collection'));
        $object->expects($this->once())
               ->method('id')
               ->will($this->returnValue('anId'));
        $object->expects($this->once())
               ->method('collection')
               ->will($this->returnValue('aCollection'));
        $ref = Morph_Utils::objectReference($object);
        $expectedArray = array(
            '$ref' => 'aCollection',
            '$id' => 'anId'
        );

        $this->assertEquals($ref, $expectedArray);
    }

}
Something went wrong with that request. Please try again.