/** * Will test if valid scalar type array is kept sane * * @return null */ public function testGetValidScalarTypes() { $validScalarTypes = $this->testClass->getValidScalarTypes(); $this->assertContains('void', $validScalarTypes); $this->assertContains('string', $validScalarTypes); $this->assertNotContains('mixed', $validScalarTypes); }
/** * Will get the conditions for a certain assertion indicating keyword like @requires or, if configured, @param * * @param string $docBlock The DocBlock to search in * @param string $conditionKeyword The keyword we are searching for, use assertion defining tags here! * @param boolean|null $privateContext If we have to mark the parsed annotations as having a private context * as we would have trouble finding out for ourselves. * * @return boolean|\AppserverIo\Doppelgaenger\Entities\Lists\AssertionList */ public function getConditions($docBlock, $conditionKeyword, $privateContext = null) { // There are only 3 valid condition types if ($conditionKeyword !== Requires::ANNOTATION && $conditionKeyword !== Ensures::ANNOTATION && $conditionKeyword !== Invariant::ANNOTATION) { return false; } // get the annotations for the passed condition keyword $annotations = $this->getAnnotationsByType($docBlock, $conditionKeyword); // if we have to enforce basic type safety we need some more annotations if ($this->config->getValue('enforcement/enforce-default-type-safety') === true) { // lets switch the switch ($conditionKeyword) { case Ensures::ANNOTATION: // we have to consider @return annotations as well $annotations = array_merge($annotations, $this->getAnnotationsByType($docBlock, 'return')); break; case Requires::ANNOTATION: // we have to consider @param annotations as well $annotations = array_merge($annotations, $this->getAnnotationsByType($docBlock, 'param')); break; default: break; } } // lets build up the result array $assertionFactory = new AssertionFactory(); $result = new AssertionList(); foreach ($annotations as $annotation) { // try to create assertion instances for all annotations try { $assertion = $assertionFactory->getInstance($annotation); } catch (\Exception $e) { error_log($e->getMessage()); continue; } if ($assertion !== false) { // Do we already got a private context we can set? If not we have to find out four ourselves if ($privateContext !== null) { // Add the context (wether private or not) $assertion->setPrivateContext($privateContext); } else { // Add the context (private or not) $this->determinePrivateContext($assertion); } // finally determine the minimal scope of this assertion and add it to our result $this->determineMinimalScope($assertion); $result->add($assertion); } } return $result; }