我想了解基于相关实体订购Doctrine Collection的最佳方法.在这种情况下,无法使用@orderBy注释.
我在互联网上找到了5个解决方案.
1)向AbstractEntity添加方法(根据Ian Belter /sf/answers/1552846921/)
/**
* This method will change the order of elements within a Collection based on the given method.
* It preserves array keys to avoid any direct access issues but will order the elements
* within the array so that iteration will be done in the requested order.
*
* @param string $property
* @param array $calledMethods
*
* @return $this
* @throws \InvalidArgumentException
*/
public function orderCollection($property, $calledMethods = array())
{
/** …Run Code Online (Sandbox Code Playgroud) 我正在symfony2开发一个项目,我是单元测试的新手.
我已经通过PEAR安装了PHPUnit 3.6.10,当我对phpunit命令进行编号时,它可以在终端上运行.
我按照SensioLab建议(http://symfony.com/doc/current/book/testing.html)编写了我的第一个测试类,但是当我使用命令时
php -c app src/My/CalendarBundle/Tests/Calendar/CalendarTest.php
Run Code Online (Sandbox Code Playgroud)
我有
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /Library/WebServer/Documents/calendar/src/My/CalendarBundle/Tests/Calendar/CalendarTest.php on line 7
Run Code Online (Sandbox Code Playgroud)
在这里,您是我的测试类:
<?php
namespace My\CalendarBundle\Tests\Calendar;
use My\CalendarBundle\Calendar\Calendar;
class CalendarTest extends \PHPUnit_Framework_TestCase
{
public function testGetNextMonth()
{
$calendar = new Calendar('09', '2012', null);
$result = $calendar->getNextMonth();
$this->assertEquals(10, $result);
}
}
Run Code Online (Sandbox Code Playgroud)
我读了这个讨论为什么,致命的错误:类'PHPUnit_Framework_TestCase'找不到...?但symfony文档并未说明包含PHPUnit ...
我做错了什么?谢谢
RI希望将控制台命令存储到变量中.我已经尝试过以下链接中提出的解决方案,但没有运气:在R中,是否可以将控制台输出重定向到变量? 这是你正在使用的命令:
test <- capture.output(system("pa11y scuolafalconeborsellino.it;
perl -e \"print unpack('c', pack('C', $?)), \\$/\""), file = NULL)
Run Code Online (Sandbox Code Playgroud)
控制台中可见的输出是:
[4m [36m欢迎来到Pa11y [39m [24m [90m]我们现在为您嗅探您的页面.[39m [36m] [39mL加载页面... [36m> [39m运行HTML CodeSniffer ... [36m> [39m [31mError:HTML CodeSniffer error [39m]
-1
但是变量测试是空的.
谢谢!
我正在使用PHPUnit测试Symfony2项目中使用的类的私有方法.我正在使用许多开发人员描述的私有方法测试策略(通过反射),例如http://aaronsaray.com/blog/2011/08/16/testing-protected-and-private-attributes-and-methods-using -phpunit /
但不幸的是,我收到以下错误:
有1个错误:1)我的\ CalendarBundle\Tests\Calendar\CalendarTest :: testCalculateDaysPreviousMonth ReflectionException:类日历不存在/Library/WebServer/Documents/calendar/src/My/CalendarBundle/Tests/Calendar/CalendarTest.php:47
<?php
namespace My\CalendarBundle\Tests\Calendar;
use My\CalendarBundle\Calendar\Calendar;
class CalendarTest
{
//this method works fine
public function testGetNextYear()
{
$this->calendar = new Calendar('12', '2012', $this->get('translator'));
$result = $this->calendar->getNextYear();
$this->assertEquals(2013, $result);
}
public function testCalculateDaysPreviousMonth()
{
$reflectionCalendar = new \ReflectionClass('Calendar'); //this is the line
$method = $reflectionCalendar->getMethod('calculateDaysPreviousMonth');
$method->setAccessible(true);
$this->assertEquals(5, $method->invokeArgs($this->calendar, array()));
}
}
Run Code Online (Sandbox Code Playgroud)
为什么?
先感谢您