将 PHPUnit 与 CakePHP 1.3 集成
我一直在寻找教程来帮助我将 PHPUnit 与 CakePHP 集成。也希望使用 Selenium 测试,所以更喜欢 PHPUnit。
我一直在尝试遵循 http://cakebaker.42dh.com/2006 上的教程/03/22/selenium/ 但似乎无法让它工作。有什么好的教程吗?
谢谢!
I have been looking for a tutorial to help me integrate PHPUnit with CakePHP. Looking to use Selenium tests too so prefer PHPUnit.
I have been trying to follow the tutorial on http://cakebaker.42dh.com/2006/03/22/selenium/ but cant seem to get it work. Any good tutorials out there?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这相对容易。我使用来自composer安装的cake 1.3。这就是我的composer.json 的样子:
然后是tests 目录中的phpunit bootstrap.php 文件:
这是同一目录中的phpunit.xml:
不要忘记在测试设置中加载应用程序类。你可以用 cakephp 的方式来做。例如,如果您的控制器名为 calendar,则 calendarTest.php 可能如下所示:
模型、供应商类等相同。对我来说效果很好。
It's relatively easy. I use cake 1.3 from composer installation. This is how my composer.json looks like:
Then the phpunit bootstrap.php file in tests directory:
This is phpunit.xml form the same dir:
Don't forget to load your application classes in test setup. You can do it cakephp way. For example if your controller is named calendar your calendarTest.php may look like:
The same for models, vendor classes and so on. Works great for me.
不幸的是,CakePHP 的设计目的不是与 PHPUnit 一起工作。 CakePHP 已切换为使用 SimpleTest,您将有两个选择之一:重构您的测试以使用 SimpleTest 或修改核心以使用 PHPUnit。
不过需要说明的是,Mark Story 已声明 CakePHP 2.0 将使用 PHPUnit 因为它是测试框架,所以如果你能等到那时,这可能会是最好的选择。
CakePHP 1.3 测试书籍
Unfortunately CakePHP isn't designed to work together with PHPUnit. CakePHP has switched to using SimpleTest and you'll have one of two choices, refactor your tests to work with SimpleTest or modify the core to use PHPUnit.
However it should be stated that Mark Story has stated that CakePHP 2.0 will use PHPUnit for it's testing framework, so if you can aford to wait till then that may wind up being the best option.
CakePHP 1.3 Book on Testing