openbuildings/kohana-test-bootsrap

此包已被弃用,不再维护。作者建议使用openbuildings/kohana-test-bootstrap包。

Kohana模块测试的辅助包

0.2.0 2016-07-28 14:07 UTC

This package is auto-updated.

Last update: 2022-02-01 12:26:00 UTC


README

用于单独测试Kohana模块 - 一个包含所有Kohana框架系统和核心模块的Composer包。

如果您想编写并独立测试一个模块(例如通过某些云CI工具)- 则需要Kohana环境,而且它尚未在composer中提供,可能会存在问题。此包添加了所有Kohana自动加载和级联文件系统,以及核心模块,您可以根据需要启用它们。

用法

由于其目的是用于测试,建议将其放置在composer.json的require-dev部分,如下所示

"require-dev": { "openbuildings/kohana-test-bootsrap": "dev-master" }

之后,您应该在测试文件夹中创建一个"test bootstrap文件",如下所示

tests/bootstrap.php
require_once __DIR__.'/../vendor/autoload.php';

Kohana::modules(array(
	// Add some core kohaan modules
	'database' => MODPATH.'database',
	'cache'    => MODPATH.'cache',
	// Your own module - this is where the module you are testing will appear in kohana's cascading filesystem
	'functest' => __DIR__.'/..',
	// Any other kohana modules, required with composer.json can be added like this
	'test'     => __DIR__.'/../tests/testmodule',
));

// Add some custom configuration, to be used only in testing - for example we adda a database config.
Kohana::$config
	->load('database')
		->set(Kohana::TESTING, array(
			'type'       => 'MySQL',
			'connection' => array(
				'hostname'   => 'localhost',
				'database'   => 'test-functest',
				'username'   => 'root',
				'password'   => '',
				'persistent' => TRUE,
			),
			'table_prefix' => '',
			'charset'      => 'utf8',
			'caching'      => FALSE,
		));

一个示例phpunit可能如下所示

phpunit.xml
<phpunit colors="true" bootstrap="tests/bootstrap.php">
	<testsuites>
		<testsuite>
			<directory>tests/tests</directory>
		</testsuite>
	</testsuites>
	<filter>
		<blacklist>
			<directory suffix=".php">vendor/</directory>
		</blacklist>
	</filter>
</phpunit>

它将tests/bootstrap.php分配为phpunit的引导文件。

作者

由Ivan Kerin在clippings.com开发