sakharovmaksim/annotation-processor

用于解析测试方法描述中的常量的实用程序。由tutu.ru创建

1.0.3 2018-05-17 14:11 UTC

This package is auto-updated.

Last update: 2024-09-13 22:42:27 UTC


README

安装

1. 从仓库下载项目

导航到您想存储项目目录的目录。例如,您的家目录 cd ~

git clone git@github.com:sakharovmaksim/annotation-processor.git

下载完成后,导航到项目目录 cd annotation-processor

2. 安装依赖项

composer install

用法

1. 在您的TestCase类中

在您的TestCase类中,setUp()方法,它继承自\PHPUnit\Framework\TestCase,创建并使用以下函数:

public function setUp()
{
	$this->_processAnnotations();
}

private function _processAnnotations()
{
	$class = get_class($this);
	$methodName = $this->getName(false);
	$annotationProcessor = new AnnotationProcessor($class, $methodName);
	// @domains
	if ($domainsExcept = $annotationProcessor->process(new Annotation\ArrayAnnotation(AnnotationsNames::DOMAINS_EXCEPT)))
	{
		if (Env::isRC() && in_array(Env::RC, $domainsExcept))
		{
			$this->markTestSkipped("Skip the test that is not for RC: {$class}::{$methodName}");
		}
		elseif (Env::isProduction() && in_array(Env::PROD, $domainsExcept))
		{
			$this->markTestSkipped("Skip the test that is not for Production: {$class}::{$methodName}");
		}
		elseif (Env::isStand() && in_array(Env::STAND, $domainsExcept))
		{
			$this->markTestSkipped("Skip the test that is not for stands: {$class}::{$methodName}");
		}
	}
	// @bug
	if ($annotationProcessor->process(new Annotation\BoolAnnotation(AnnotationsNames::BUG)))
	{
		$this->markTestSkipped("Skip the test {$class}::{$methodName}, because it has deactivated due to a @bug!");
	}
	// @todocase
	if ($annotationProcessor->process(new Annotation\BoolAnnotation(AnnotationsNames::TODOCASE)))
	{
		$this->markTestSkipped("Skip the test {$class}::{$methodName}, because it has @todocase, write it!");
	}
}

此函数在每次测试开始时将分析描述中的常量,并应用上述函数中描述的操作。

2. 创建包含注解常量的AnnotationsNames文件

在_processAnnotations()中使用常量

class AnnotationsNames
{
	const DOMAINS_EXCEPT = '@domainsExcept';
	const BUG = '@bug';
	const TODOCASE = '@todocase';
}

3. 在测试注解中的用法

/**
 * @labels Labels::RELEASE
 * @todocase Проверка поиска "Только туда"
 */
public function testSearchOW() {}

4. 运行项目的单元测试

sh run_tests.sh

5. 部署

Travis CI为所有Pull Request运行单元测试。查看'.travis.yml'文件中的CI配置

由tutu.ru创建