コード例 #1
0
    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp()
    {
        // mock the adapter, driver, and parts
        $mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
        $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(5));

        $mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
        $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult));

        $mockConnection = $this->getMock('Zend\Db\Adapter\Driver\ConnectionInterface');
        $mockConnection->expects($this->any())->method('getLastGeneratedValue')->will($this->returnValue(10));

        $mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
        $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
        $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection));

        $this->mockAdapter = $this->getMock('Zend\Db\Adapter\Adapter', null, array($mockDriver));
        $this->mockSql = $this->getMock('Zend\Db\Sql\Sql', array('select', 'insert', 'update', 'delete'), array($this->mockAdapter, 'foo'));
        $this->mockSql->expects($this->any())->method('select')->will($this->returnValue($this->getMock('Zend\Db\Sql\Select', array('where', 'getRawSate'), array('foo'))));
        $this->mockSql->expects($this->any())->method('insert')->will($this->returnValue($this->getMock('Zend\Db\Sql\Insert', array('prepareStatement', 'values'), array('foo'))));
        $this->mockSql->expects($this->any())->method('update')->will($this->returnValue($this->getMock('Zend\Db\Sql\Update', array('where'), array('foo'))));
        $this->mockSql->expects($this->any())->method('delete')->will($this->returnValue($this->getMock('Zend\Db\Sql\Delete', array('where'), array('foo'))));

        $this->table = $this->getMockForAbstractClass(
            'Zend\Db\TableGateway\AbstractTableGateway'
            //array('getTable')
        );
        $tgReflection = new \ReflectionClass('Zend\Db\TableGateway\AbstractTableGateway');
        foreach ($tgReflection->getProperties() as $tgPropReflection) {
            $tgPropReflection->setAccessible(true);
            switch ($tgPropReflection->getName()) {
                case 'table':
                    $tgPropReflection->setValue($this->table, 'foo');
                    break;
                case 'adapter':
                    $tgPropReflection->setValue($this->table, $this->mockAdapter);
                    break;
                case 'resultSetPrototype':
                    $tgPropReflection->setValue($this->table, new ResultSet);
                    break;
                case 'sql':
                    $tgPropReflection->setValue($this->table, $this->mockSql);
                    break;
            }
        }
    }
コード例 #2
0
ファイル: TableGatewayTest.php プロジェクト: rikaix/zf2
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     // mock the adapter, driver, and parts
     $mockResult = $this->getMock('Zend\\Db\\Adapter\\Driver\\ResultInterface');
     $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(5));
     $mockStatement = $this->getMock('Zend\\Db\\Adapter\\Driver\\StatementInterface');
     $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult));
     $mockConnection = $this->getMock('Zend\\Db\\Adapter\\Driver\\ConnectionInterface');
     $mockConnection->expects($this->any())->method('getLastGeneratedValue')->will($this->returnValue(10));
     $mockDriver = $this->getMock('Zend\\Db\\Adapter\\Driver\\DriverInterface');
     $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
     $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection));
     $this->mockAdapter = $this->getMock('Zend\\Db\\Adapter\\Adapter', null, array($mockDriver));
     $this->mockSql = $this->getMock('Zend\\Db\\Sql\\Sql', array('select', 'insert', 'update', 'delete'), array($this->mockAdapter, 'foo'));
     $this->mockSql->expects($this->any())->method('select')->will($this->returnValue($this->getMock('Zend\\Db\\Sql\\Select', array('where', 'getRawSate'), array('foo'))));
     $this->mockSql->expects($this->any())->method('insert')->will($this->returnValue($this->getMock('Zend\\Db\\Sql\\Insert', array('prepareStatement', 'values'), array('foo'))));
     $this->mockSql->expects($this->any())->method('update')->will($this->returnValue($this->getMock('Zend\\Db\\Sql\\Update', array('where'), array('foo'))));
     $this->mockSql->expects($this->any())->method('delete')->will($this->returnValue($this->getMock('Zend\\Db\\Sql\\Delete', array('where'), array('foo'))));
     $this->table = new TableGateway('foo', $this->mockAdapter, null, $this->mockSql);
 }
コード例 #3
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     // mock the adapter, driver, and parts
     $mockResult = $this->getMock('Zend\\Db\\Adapter\\Driver\\ResultInterface');
     $mockResult->expects($this->any())->method('getAffectedRows')->will($this->returnValue(5));
     $mockResult->expects($this->any())->method('current')->will($this->returnValue(5));
     $mockStatement = $this->getMock('Zend\\Db\\Adapter\\Driver\\StatementInterface');
     $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult));
     $mockConnection = $this->getMock('Zend\\Db\\Adapter\\Driver\\ConnectionInterface');
     $mockConnection->expects($this->any())->method('getLastGeneratedValue')->will($this->returnValue(10));
     $mockDriver = $this->getMock('Zend\\Db\\Adapter\\Driver\\DriverInterface');
     $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
     $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection));
     $this->mockAdapter = $this->getMock('Zend\\Db\\Adapter\\Adapter', null, array($mockDriver));
     $this->mockSql = $this->getMock('Zend\\Db\\Sql\\Sql', array('select', 'insert', 'update', 'delete'), array($this->mockAdapter, 'foo'));
     $this->mockSql->expects($this->any())->method('select')->will($this->returnValue($this->getMock('Zend\\Db\\Sql\\Select', array('where', 'getRawSate'), array('foo'))));
     $this->mockSql->expects($this->any())->method('insert')->will($this->returnValue($this->getMock('Zend\\Db\\Sql\\Insert', array('prepareStatement', 'values'), array('foo'))));
     $this->mockSql->expects($this->any())->method('update')->will($this->returnValue($this->getMock('Zend\\Db\\Sql\\Update', array('where'), array('foo'))));
     $this->mockSql->expects($this->any())->method('delete')->will($this->returnValue($this->getMock('Zend\\Db\\Sql\\Delete', array('where'), array('foo'))));
     $this->table = $this->getMockForAbstractClass('VisioCrudModeler\\Model\\TableGateway\\AbstractTable', array($this->mockAdapter, 'test'));
     $tgReflection = new \ReflectionClass('VisioCrudModeler\\Model\\TableGateway\\AbstractTable');
     foreach ($tgReflection->getProperties() as $tgPropReflection) {
         $tgPropReflection->setAccessible(true);
         switch ($tgPropReflection->getName()) {
             case 'adapter':
                 $tgPropReflection->setValue($this->table, $this->mockAdapter);
                 break;
             case 'sql':
                 $tgPropReflection->setValue($this->table, $this->mockSql);
                 break;
             case 'keyName':
                 $tgPropReflection->setValue($this->table, 'id');
                 break;
             case 'table':
                 $tgPropReflection->setValue($this->table, 'foo');
                 break;
         }
     }
     $this->entity = $this->getMock('VisioCrudModeler\\Model\\TableGateway\\Entity\\AbstractEntity');
     $this->entity->expects($this->any())->method('getArrayCopy')->will($this->returnValue(array('id' => 5, 'foo' => 'bar')));
 }