| @@ 21-99 (lines=79) @@ | ||
| 18 | * @since class available since Release 0.9.1 |
|
| 19 | * @version 0.9.4 |
|
| 20 | */ |
|
| 21 | class ValidatorClassNameMethodAccess extends BaseCoverFishValidator |
|
| 22 | { |
|
| 23 | /** |
|
| 24 | * @return array |
|
| 25 | */ |
|
| 26 | private function execute() |
|
| 27 | { |
|
| 28 | preg_match_all('/^(?P<class>(^(([\\\\])|([A-Z]))([A-Za-z0-9_\\\\]+)))(?P<sep>::{1})((<{1})(?P<accessor>[!\w]+)(>{1})\s*\Z)$/', $this->coversToken, $this->result, PREG_SET_ORDER); |
|
| 29 | ||
| 30 | return $this->result; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * @return bool |
|
| 35 | */ |
|
| 36 | public function validate() |
|
| 37 | { |
|
| 38 | return (count($this->execute()) > 0) && $this->validateResultKeys(); |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * @return bool |
|
| 43 | */ |
|
| 44 | public function validateResultKeys() |
|
| 45 | { |
|
| 46 | return array_key_exists('class', $this->getResult()) |
|
| 47 | && array_key_exists('sep', $this->getResult()) |
|
| 48 | && array_key_exists('accessor', $this->getResult() |
|
| 49 | ); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * @param CoverFishPHPUnitFile $phpUnitFile |
|
| 54 | * |
|
| 55 | * @return CoverFishMapping |
|
| 56 | */ |
|
| 57 | public function getMapping(CoverFishPHPUnitFile $phpUnitFile) |
|
| 58 | { |
|
| 59 | $accessor = $this->getResult()['accessor']; |
|
| 60 | $class = $this->getResult()['class']; |
|
| 61 | $classFQN = $this->coverFishHelper->getClassFromUse($class, $phpUnitFile->getUsedClasses()); |
|
| 62 | ||
| 63 | $mappingOptions = array( |
|
| 64 | 'coverToken' => $this->coversToken, |
|
| 65 | 'coverMethod' => null, |
|
| 66 | 'coverAccessor' => $accessor, |
|
| 67 | 'coverClass' => $class, |
|
| 68 | 'coverClassFQN' => $classFQN, |
|
| 69 | 'validatorMatch' => $this->getValidationTag(), |
|
| 70 | 'validatorClass' => get_class($this) |
|
| 71 | ); |
|
| 72 | ||
| 73 | return $this->setMapping($mappingOptions); |
|
| 74 | } |
|
| 75 | ||
| 76 | /** |
|
| 77 | * @return string |
|
| 78 | */ |
|
| 79 | public function getValidationInfo() |
|
| 80 | { |
|
| 81 | return 'Specifies that the annotated test method covers the specified method.'; |
|
| 82 | } |
|
| 83 | ||
| 84 | /** |
|
| 85 | * @return string |
|
| 86 | */ |
|
| 87 | public function getValidationTag() |
|
| 88 | { |
|
| 89 | return 'ClassName::<public|protected|private|!public|!protected|!private>'; |
|
| 90 | } |
|
| 91 | ||
| 92 | /** |
|
| 93 | * @return string |
|
| 94 | */ |
|
| 95 | public function __toString() |
|
| 96 | { |
|
| 97 | return get_class($this); |
|
| 98 | } |
|
| 99 | } |
|
| @@ 20-98 (lines=79) @@ | ||
| 17 | * @since class available since Release 0.9.0 |
|
| 18 | * @version 0.9.4 |
|
| 19 | */ |
|
| 20 | class ValidatorClassNameMethodName extends BaseCoverFishValidator |
|
| 21 | { |
|
| 22 | /** |
|
| 23 | * @return array |
|
| 24 | */ |
|
| 25 | private function execute() |
|
| 26 | { |
|
| 27 | preg_match_all('/^(?P<class>(^(([\\\\])|([A-Z]))([A-Za-z0-9_\\\\]+)))(?P<sep>::{1})((?P<method>[\w]+))$/', $this->coversToken, $this->result, PREG_SET_ORDER); |
|
| 28 | ||
| 29 | return $this->result; |
|
| 30 | } |
|
| 31 | ||
| 32 | /** |
|
| 33 | * @return bool |
|
| 34 | */ |
|
| 35 | public function validate() |
|
| 36 | { |
|
| 37 | return (count($this->execute()) > 0) && $this->validateResultKeys(); |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * @return bool |
|
| 42 | */ |
|
| 43 | public function validateResultKeys() |
|
| 44 | { |
|
| 45 | return array_key_exists('class', $this->getResult()) |
|
| 46 | && array_key_exists('sep', $this->getResult()) |
|
| 47 | && array_key_exists('method', $this->getResult() |
|
| 48 | ); |
|
| 49 | } |
|
| 50 | ||
| 51 | /** |
|
| 52 | * @param CoverFishPHPUnitFile $phpUnitFile |
|
| 53 | * |
|
| 54 | * @return CoverFishMapping |
|
| 55 | */ |
|
| 56 | public function getMapping(CoverFishPHPUnitFile $phpUnitFile) |
|
| 57 | { |
|
| 58 | $method = $this->getResult()['method']; |
|
| 59 | $class = $this->getResult()['class']; |
|
| 60 | $classFQN = $this->coverFishHelper->getClassFromUse($class, $phpUnitFile->getUsedClasses()); |
|
| 61 | ||
| 62 | $mappingOptions = array( |
|
| 63 | 'coverToken' => $this->coversToken, |
|
| 64 | 'coverMethod' => $method, |
|
| 65 | 'coverAccessor' => null, |
|
| 66 | 'coverClass' => $class, |
|
| 67 | 'coverClassFQN' => $classFQN, |
|
| 68 | 'validatorMatch' => $this->getValidationTag(), |
|
| 69 | 'validatorClass' => get_class($this) |
|
| 70 | ); |
|
| 71 | ||
| 72 | return $this->setMapping($mappingOptions); |
|
| 73 | } |
|
| 74 | ||
| 75 | /** |
|
| 76 | * @return string |
|
| 77 | */ |
|
| 78 | public function getValidationInfo() |
|
| 79 | { |
|
| 80 | return 'Specifies that the annotated test method covers the specified method.'; |
|
| 81 | } |
|
| 82 | ||
| 83 | /** |
|
| 84 | * @return string |
|
| 85 | */ |
|
| 86 | public function getValidationTag() |
|
| 87 | { |
|
| 88 | return 'ClassName::methodName'; |
|
| 89 | } |
|
| 90 | ||
| 91 | /** |
|
| 92 | * @return string |
|
| 93 | */ |
|
| 94 | public function __toString() |
|
| 95 | { |
|
| 96 | return get_class($this); |
|
| 97 | } |
|
| 98 | } |
|