powered by nequal
Home » Packages » Net_Cicindela » Source

Net_Cicindela / trunk/tests/src/Net/Net_CicindelaTest.php

Subversion URL: http://svn.openpear.org/Net_Cicindela/trunk/tests/src/Net/Net_CicindelaTest.php

Recent change

MugeSo [2461] -- 2011-05-12 15:00:23
テストが正しく通らない問題を修正

<?php
ini_set("include_path", realpath(dirname(__FILE__) . "/../../../src").PATH_SEPARATOR.ini_get("include_path"));
require_once 'PHPUnit/Framework.php';
 
PHPUnit_Util_Filter::addDirectoryToFilter('C:\php\pear');
require_once 'Net/Cicindela.php';
 
/**
 * Test class for Net_Cicindela.
 * Generated by PHPUnit on 2009-06-11 at 11:10:41.
 */
class Net_CicindelaTest extends PHPUnit_Framework_TestCase
{
/**
 * @var    Net_Cicindela
 * @access protected
 */
    protected $object;
 
    protected $requestStab;
 
    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     *
     * @access protected
     */
    protected function setUp()
    {
        $this->requestStab = $this->getMock('HTTP_Request2');
        $this->object = new Net_Cicindela('http://localhost/cicindela/', $this->requestStab);
    }
 
    /**
     * Tears down the fixture, for example, closes a network connection.
     * This method is called after a test is executed.
     *
     * @access protected
     */
    protected function tearDown()
    {
    }
 
    /**
     *
     */
    public function testGetDataset() {
        $dataset = $this->object->getDataset('foo');
        $this->assertType('Net_Cicindela_Dataset', $dataset);
    }
 
    /**
     *
     */
    public function testGetBaseUrl() {
        $this->assertEquals('http://localhost/cicindela/', $this->object->getBaseUrl());
    }
 
    /**
     *
     */
    public function testRecord() {
        $responseStab = $this->getMock('HTTP_Request2_Response', array('getStatus'));
        $responseStab->expects($this->once())
            ->method('getStatus')
            ->will($this->returnValue(204));
 
        $requestStab = $this->requestStab;
        $requestStab->expects($this->once())->method('setUrl');
        $requestStab->expects($this->once())->method('send')
            ->will($this->returnValue($responseStab));
 
        $param['op'] = 'insert_pick';
        $this->object->record($param);
    }
 
    /**
     * @expectedException RuntimeException
     */
    public function testRecordBadrequest() {
        $responseStab = $this->getMock('HTTP_Request2_Response', array('getStatus'));
        $responseStab->expects($this->once())
            ->method('getStatus')
            ->will($this->returnValue(400));
 
        $requestStab = $this->requestStab;
        $requestStab->expects($this->once())->method('setUrl');
        $requestStab->expects($this->any())->method('send')
            ->will($this->returnValue($responseStab));
 
        $param['op'] = 'insert_pick';
        $this->object->record($param);
    }
 
    /**
     *
     */
    public function testGetRecommend() {
        $responseStab = $this->getMock('HTTP_Resuest2_Response', array('getStatus', 'getBody'));
        $responseStab->expects($this->any())
            ->method('getStatus')
            ->will($this->returnValue(200));
        $responseStab->expects($this->any())
            ->method('getBody')
            ->will($this->returnValue("11111\n22222\n33333\n44444\n"));
 
        $requestStab = $this->requestStab;
        $requestStab->expects($this->once())->method('setUrl');
        $requestStab->expects($this->once())->method('send')
            ->will($this->returnValue($responseStab));
 
 
        $param['op'] = 'for_item';
        $this->assertEquals(array('11111', '22222', '33333', '44444'), $this->object->getRecommend($param));
    }
 
 
    /**
     * @expectedException RuntimeException
     */
    public function testGetRecommendBadresponse() {
        $responseStab = $this->getMock('HTTP_Resuest2_Response', array('getStatus', 'getBody'));
        $responseStab->expects($this->any())
            ->method('getStatus')
            ->will($this->returnValue(400));
        $responseStab->expects($this->never())
            ->method('getBody');
 
        $requestStab = $this->requestStab;
        $requestStab->expects($this->once())->method('setUrl');
        $requestStab->expects($this->once())->method('send')
            ->will($this->returnValue($responseStab));
 
        $param['op'] = 'for_item';
        $this->object->getRecommend($param);
    }
}
?>