webino / webino-dev
Zend Framework 2 的 Webino 开发者模块
dev-develop
2022-06-25 16:01 UTC
Requires
- php: >=7.1
- ext-dom: *
- ext-libxml: *
- rwoverdijk/assetmanager: 1.6.*
- webino/zend-db-profiler: 1.*
Requires (Dev)
- kriswallsmith/assetic: 1.*
- phpunit/phpunit: 4.*
- webino/zend-mail: 2.6.*
- zendframework/zend-code: 2.*
- zendframework/zend-console: 2.*
- zendframework/zend-di: 2.*
- zendframework/zend-http: 2.*
- zendframework/zend-log: 2.*
- zendframework/zend-modulemanager: 2.*
- zendframework/zend-mvc: 2.6.*
- zendframework/zend-session: 2.*
- zendframework/zend-version: 2.*
- zendframework/zend-view: 2.*
Suggests
- element-34/php-webdriver: Selenium tests
- exorus/php-mime-mail-parser: Mail parser
- kriswallsmith/assetic: Filesystem cache umask fix
- mikey179/vfsStream: Virtual filesystem
- nette/tester: Better tests runner (instead of PHPUnit)
- phpunit/phpunit: PHPUnit tests support (deprecated)
- smalot/pdfparser: PDF parser
- webino/webino-debug: Better var dumping
- zendframework/zend-code: To use DI definition generator (deprecated)
- zendframework/zend-di: To use DI definition generator (deprecated)
- zendframework/zend-mail: Mail testing
- zendframework/zend-modulemanager: To use as a Zend Framework module
This package is auto-updated.
Last update: 2024-08-25 20:29:47 UTC
README
简化 Webino 模块开发的模块。
特性
- 实用函数
- 智能依赖注入定义生成器(已弃用)
- DOM 测试
- 邮件测试
- Selenium 抽象测试测试
- Selenium WebDriver 测试的基础类
- 身份验证测试
- 表单测试
- AJAX 测试
- 浏览器截图
- 视频调试通知支持
- 使用 umask 修复 Assetic\Cache\FilesystemCache 文件权限
要求
- PHP 7.1
- ZendFramework 2
设置
打开终端并转到您的应用程序目录
- 仅在您的开发环境中使用此模块
- 运行
php composer.phar require webino/webino-dev:dev-develop
- 将
WebinoDev
添加到启用模块列表
注意:考虑到 zf2-skeleton 或非常类似的应用程序。
快速入门
实用函数
d(); // var_dump(); dd(); // var_dump();exit; p(); // print_r(); pd(); // print_r();exit; pr(); // return print_r(); e(); // throw new \WebinoDev\Exception\DevelopmentException;
依赖注入定义生成器
在您的模块中创建名为 bin/definition_generator
的文件,代码如下
#!/usr/bin/env php <?php namespace WebinoExample; use WebinoDev\Di\Definition\Generator; // Autoloader $loader = require __DIR__ . '/../vendor/autoload.php'; $loader->add(__NAMESPACE__, __DIR__ . '/../src'); // Dump DI definition (new Generator(__DIR__))->compile()->dump();
注意:假设 WebinoExample/bin/
和 WebinoExample/vendor/
目录。
注意:使用您的命名空间而不是 WebinoExample。
使用相对于 vendor 目录的路径
(new Generator(__DIR__))->compile(['custom/path/1', 'custom/path/2'])->dump();
使用忽略的路径
(new Generator(__DIR__))->setIgnore(['regex1', 'regex2', 'etc.'])->compile()->dump();
Selenium WebDriver 测试
use WebinoDev\Test\Selenium\AbstractTestCase; class HomeTest extends AbstractTestCase { public function testHome() { $this->openOk('page/path'); $this->clickLink('Link example'); /** * Use following methods to get a page element * * It's possible to use $this->elementsBy... to get array of elements also. */ $this->elementByClassName('class-name'); $this->elementByCssSelector('.class-name tagname'); $this->elementById('test-id'); $this->elementByLinkText('Test link'); $this->elementByName('test_name'); $this->elementByPartialLinkText('Link text too long'); $this->elementByTagName('tagname'); $this->elementByXpath('//test/xpath'); /** * Screenshots */ $data = $this->screenshot(); // or $this->attachScreenshot('Example caption'); } }
测试 DOM
use WebinoDev\Test\DomTrait; /** * Concrete test trait */ class DomTestCase extends \PHPUnit_Framework_TestCase { use DomTrait; public function testDom() { $xhtml = '<html/>'; $dom = $this->createDom($xhtml); $elm = $dom->xpath->query('//html')->item(0); $this->assertNotNull($elm); } }
测试身份验证
use WebinoDev\Test\Selenium\AbstractAuthenticationTestCase; class AuthenticationTest extends AbstractAuthenticationTestCase { public function testAuthentication() { $this->openOk(); $this->setAuthSuccessLocator('.authentication-success'); $this->authenticate(); } }
或使用特质
use WebinoDev\Test\Selenium\AbstractTestCase; class AuthenticationTest extends AbstractTestCase { use AuthenticationTrait; }
测试表单
use WebinoDev\Test\Selenium\AbstractTestCase; class HomeTest extends AbstractTestCase { public function testHome() { $this->submitImput('email', 'test@example.com'); // or $this->enterInput('email', 'test@example.com', function ($elm) { $elm->submit(); }); $this->assertInput('email', 'test@example.com'); $this->waitFor( function () { return $this->elementByClassName('example-success'); }, function ($elm) { $this->assertSame('example', $elm->text()); } ); } }
测试 AJAX
use WebinoDev\Test\Selenium\AbstractTestCase; class HomeTest extends AbstractTestCase { public function testHome() { $this->clickAjaxLink(); // or $this->elementByClassName('ajax-btn')->click(); $this->waitForAjax(); // or with delay 2 seconds $this->waitForAjax(2); $result = $this->elementByClassName('ajax-result')->text(); $this->assertSame('expected ajax result', $result); } }
测试邮件
支持功能性和 Selenium 邮件测试。
功能性邮件测试
假设邮件消息已保存为虚拟文件系统 tmp/mail
目录中的文件。
注意:使用 org\bovigo\vfs\vfsStream::url('root/tmp/mail')
作为虚拟文件系统目录路径。
use WebinoDev\Test\Functional\AbstractMailTestCase; class MailTest extends AbstractMailTestCase { public function testMail() { // ... $mail = $this->readMail(); $this->assertNotNull($mail); $this->assertSame($expectedSubject, $mail->getSubject()); } }
或使用特质
use WebinoDev\Test\Functional\AbstractTestCase; use WebinoDev\Test\Functional\MailTrait; class MailTest extends AbstractTestCase { use MailTrait; /** * {@inheritDoc} */ protected function setUp() { $this->setUpMailVfs(); } }
使用 Selenium 测试邮件
假设邮件消息已保存为应用程序相对路径的 tmp/mail
目录中的文件。
use WebinoDev\Test\Selenium\AbstractMailTestCase; class MailTest extends AbstractMailTestCase { public function testMail() { // ... $mail = $this->readMail(); $this->assertNotNull($mail); $this->assertSame($expectedSubject, $mail->getSubject()); } }
或使用特质
use WebinoDev\Test\Selenium\AbstractTestCase; use WebinoDev\Test\Selenium\MailTrait; class MailTest extends AbstractTestCase { use MailTrait; /** * {@inheritDoc} */ protected function setUp() { parent::setUp(); $this->setUpMailDir(); } /** * {@inheritDoc} */ protected function tearDown() { parent::tearDown(); $this->tearDownMailDir(); } }
测试抽象 Selenium 测试
use WebinoDev\Test\Functional\SeleniumTestTrait; class AbstractSeleniumTestCaseTest extends \PHPUnit_Framework_TestCase { use SeleniumTestTrait; protected $object; protected function setUp() { $this->setUpWebDriver(); $this->object = new SeleniumTestCase; $this->object->session = $this->getWebDriverSession(); } }
待办事项
- 使用 Facebook WebDriver 而不是 Element34
- 使用 Nette\Tester 而不是 PHPUnit 作为测试运行器
- 文档调试通知支持
- 升级 Zend MVC
- 升级 Zend 邮件
附录
请,如果您对这个 Zend Framework 模块感兴趣,请报告任何问题,并不要犹豫贡献。我们将非常欣赏对这个模块发展的任何贡献。