diff --git a/src/Troopers/BehatContexts/Collection/MailCollection.php b/src/Troopers/BehatContexts/Collection/MailCollection.php index 7873e87..f7a478f 100644 --- a/src/Troopers/BehatContexts/Collection/MailCollection.php +++ b/src/Troopers/BehatContexts/Collection/MailCollection.php @@ -1,13 +1,12 @@ files()->in($this->rootDir.'/'.$path); $result = []; - if(!$finder->count()) - { + if (!$finder->count()) { throw new FileNotFoundException('No configuration found'); } // read yaml config files @@ -49,18 +51,16 @@ public function load($path, $key) 'The file located in '.$configFile.' has no config value "'.$key.'"' ); } - foreach ($config[$key] as $index => $value) - { - if(array_key_exists($index, $result)) - { + foreach ($config[$key] as $index => $value) { + if (array_key_exists($index, $result)) { throw new InvalidConfigurationException(sprintf('Duplicate key "%s" for configurations files located in %s', $index, $configFile)); } - if($value !== null) - { + if ($value !== null) { $result[$index] = $value; } } } + return $result; } -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/Component/ConfigTranslator.php b/src/Troopers/BehatContexts/Component/ConfigTranslator.php index 80790f8..42e4982 100644 --- a/src/Troopers/BehatContexts/Component/ConfigTranslator.php +++ b/src/Troopers/BehatContexts/Component/ConfigTranslator.php @@ -1,20 +1,19 @@ $translationValue] + * @param array $parameters ['translationKey' => $translationValue] * @param $firstCharacter * @param $lastCharacter + * * @throws \InvalidArgumentException */ public function rebuildTranslationKeys(array &$parameters, $firstCharacter, $lastCharacter) { $newParameters = []; foreach ($parameters as $parameter) { - if(!is_array($parameter) || count($parameter) !== 2) - { + if (!is_array($parameter) || count($parameter) !== 2) { throw new \InvalidArgumentException('Parameters given for translation does not match with [0] => \'translationKey\', [1] => $translationValue'); } $newParameters[$firstCharacter.$parameter[0].$lastCharacter] = $parameter[1]; } $parameters = $newParameters; } -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/ContentValidator/ContentValidatorException.php b/src/Troopers/BehatContexts/ContentValidator/ContentValidatorException.php index f1e9125..5aab821 100644 --- a/src/Troopers/BehatContexts/ContentValidator/ContentValidatorException.php +++ b/src/Troopers/BehatContexts/ContentValidator/ContentValidatorException.php @@ -2,11 +2,9 @@ namespace Troopers\BehatContexts\ContentValidator; - /** - * class ContentValidatorException + * class ContentValidatorException. */ class ContentValidatorException extends \Exception { - -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/ContentValidator/ContentValidatorInterface.php b/src/Troopers/BehatContexts/ContentValidator/ContentValidatorInterface.php index 4398393..cd7fb53 100644 --- a/src/Troopers/BehatContexts/ContentValidator/ContentValidatorInterface.php +++ b/src/Troopers/BehatContexts/ContentValidator/ContentValidatorInterface.php @@ -2,7 +2,8 @@ namespace Troopers\BehatContexts\ContentValidator; -interface ContentValidatorInterface { +interface ContentValidatorInterface +{ /** * @param mixed $value * @param string $content @@ -13,7 +14,6 @@ public function valid($value, $content = ''); /** * @param mixed $value - * */ public function supports($value); -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/ContentValidator/StringValidator.php b/src/Troopers/BehatContexts/ContentValidator/StringValidator.php index 7ba349c..93242e5 100644 --- a/src/Troopers/BehatContexts/ContentValidator/StringValidator.php +++ b/src/Troopers/BehatContexts/ContentValidator/StringValidator.php @@ -2,7 +2,8 @@ namespace Troopers\BehatContexts\ContentValidator; -class StringValidator implements ContentValidatorInterface { +class StringValidator implements ContentValidatorInterface +{ /** * @param mixed $value * @@ -10,8 +11,7 @@ class StringValidator implements ContentValidatorInterface { */ public function supports($value) { - if (!is_string($value)) - { + if (!is_string($value)) { throw new ContentValidatorException(sprintf('Value given (%s) is not a string', json_encode($value))); } } @@ -20,8 +20,9 @@ public function supports($value) * @param string $value * @param string $content * - * @return mixed * @throws \InvalidArgumentException + * + * @return mixed */ public function valid($value, $content = '') { @@ -29,4 +30,4 @@ public function valid($value, $content = '') throw new \InvalidArgumentException(sprintf("Unable to find text \"%s\" in current message:\n%s", $value, $content)); } } -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/ContentValidator/TableValidator.php b/src/Troopers/BehatContexts/ContentValidator/TableValidator.php index 26ac3f5..f1d5900 100644 --- a/src/Troopers/BehatContexts/ContentValidator/TableValidator.php +++ b/src/Troopers/BehatContexts/ContentValidator/TableValidator.php @@ -4,7 +4,8 @@ use DOMDocument; -class TableValidator implements ContentValidatorInterface { +class TableValidator implements ContentValidatorInterface +{ /** * @param mixed $value * @@ -12,16 +13,13 @@ class TableValidator implements ContentValidatorInterface { */ public function supports($value) { - if (!is_array($value)) - { + if (!is_array($value)) { throw new ContentValidatorException(sprintf('Value given (%s) is not an array', json_encode($value))); } else { /** @var array $value */ - foreach ($value as $index => $table) - { - if (!is_array($table)) - { - throw new ContentValidatorException(sprintf('Value given (%s) on $s row is not an array', $index+1, json_encode($table))); + foreach ($value as $index => $table) { + if (!is_array($table)) { + throw new ContentValidatorException(sprintf('Value given (%s) on $s row is not an array', $index + 1, json_encode($table))); } } } @@ -31,19 +29,19 @@ public function supports($value) * @param array $value * @param string $content * - * @return mixed * @throws \InvalidArgumentException + * + * @return mixed */ - public function valid( $value = [], $content = '') + public function valid($value = [], $content = '') { - $doc = new DOMDocument(); $doc->loadHTML($content); if (!$htmlArray = $doc->getElementById('array')) { - throw new \InvalidArgumentException("Unable to find array with id \"array\""); + throw new \InvalidArgumentException('Unable to find array with id "array"'); } /** - * @var int $lineNb + * @var int * @var array $cells */ foreach ($value as $lineNb => $cells) { @@ -55,4 +53,4 @@ public function valid( $value = [], $content = '') } } } -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/Context/ExtendedAliceContext.php b/src/Troopers/BehatContexts/Context/ExtendedAliceContext.php index 668a252..ad3193f 100644 --- a/src/Troopers/BehatContexts/Context/ExtendedAliceContext.php +++ b/src/Troopers/BehatContexts/Context/ExtendedAliceContext.php @@ -2,26 +2,24 @@ namespace Troopers\BehatContexts\Context; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\OptimisticLockException; use Doctrine\ORM\ORMInvalidArgumentException; -use Doctrine\ORM\EntityManager; use Knp\FriendlyContexts\Context\AliceContext; /** - * Class ExtendedAliceContext - * - * @package Troopers\BehatContexts\Context + * Class ExtendedAliceContext. */ -class ExtendedAliceContext extends AliceContext { - +class ExtendedAliceContext extends AliceContext +{ /** * @return array */ private function getPersistableClasses() { - $persistable = array(); - $metadatas = $this->getEntityManager()->getMetadataFactory()->getAllMetadata(); + $persistable = []; + $metadatas = $this->getEntityManager()->getMetadataFactory()->getAllMetadata(); foreach ($metadatas as $metadata) { if (isset($metadata->isEmbeddedClass) && $metadata->isEmbeddedClass) { @@ -33,10 +31,12 @@ private function getPersistableClasses() return $persistable; } + /** * @param $loader * @param $fixtures * @param $files + * * @throws OptimisticLockException * @throws ORMInvalidArgumentException */ @@ -49,8 +49,7 @@ protected function loadFixtures($loader, $fixtures, $files) if (in_array($id, $files, null)) { foreach ($loader->load($fixture) as $object) { if (in_array(get_class($object), $persistable, null)) { - if(method_exists($object, 'getId') && $object->getId()) - { + if (method_exists($object, 'getId') && $object->getId()) { $metadata = $em->getClassMetadata(get_class($object)); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); } @@ -61,4 +60,4 @@ protected function loadFixtures($loader, $fixtures, $files) } } } -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/Context/ExtendedEntityContext.php b/src/Troopers/BehatContexts/Context/ExtendedEntityContext.php index 51707b4..438ecb0 100644 --- a/src/Troopers/BehatContexts/Context/ExtendedEntityContext.php +++ b/src/Troopers/BehatContexts/Context/ExtendedEntityContext.php @@ -2,26 +2,27 @@ namespace Troopers\BehatContexts\Context; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; use Doctrine\ORM\EntityManager; use Knp\FriendlyContexts\Context\EntityContext; -use Doctrine\DBAL\Connection; /** - * Class ExtendedEntityContext - * - * @package Troopers\BehatContexts\Context + * Class ExtendedEntityContext. */ -class ExtendedEntityContext extends EntityContext { +class ExtendedEntityContext extends EntityContext +{ /** * @BeforeScenario + * * @param $event + * * @throws DBALException */ public function beforeScenario($event) { parent::beforeScenario($event); - if ($this->hasTags([ 'truncate-data', '~not-truncate-data' ])) { + if ($this->hasTags(['truncate-data', '~not-truncate-data'])) { /** @var EntityManager $entityManager */ foreach ($this->getEntityManagers() as $entityManager) { /* @var $connection Connection */ @@ -38,4 +39,4 @@ public function beforeScenario($event) } } } -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/Context/Initializer/MailInitializer.php b/src/Troopers/BehatContexts/Context/Initializer/MailInitializer.php index 8063ec9..2af0d16 100644 --- a/src/Troopers/BehatContexts/Context/Initializer/MailInitializer.php +++ b/src/Troopers/BehatContexts/Context/Initializer/MailInitializer.php @@ -4,9 +4,8 @@ use Behat\Behat\Context\Context; use Behat\Behat\Context\Initializer\ContextInitializer; -use Behat\Behat\Context\Context as ContextInterface; -use Troopers\BehatContexts\Context\MailContext; use Troopers\BehatContexts\Collection\MailCollection; +use Troopers\BehatContexts\Context\MailContext; use Troopers\BehatContexts\Mail\MailChecker; class MailInitializer implements ContextInitializer @@ -42,7 +41,6 @@ public function supports($context) public function initializeContext(Context $context) { if ($context instanceof MailContext) { - $context->initialize($this->mailCollection, $this->mailChecker); } } diff --git a/src/Troopers/BehatContexts/Context/MailContext.php b/src/Troopers/BehatContexts/Context/MailContext.php index 82e4ab0..32f41b4 100644 --- a/src/Troopers/BehatContexts/Context/MailContext.php +++ b/src/Troopers/BehatContexts/Context/MailContext.php @@ -2,7 +2,6 @@ namespace Troopers\BehatContexts\Context; - use Behat\Behat\Context\Context; use Behat\Gherkin\Node\TableNode; use Behat\MinkExtension\Context\RawMinkContext; @@ -10,16 +9,14 @@ use Troopers\BehatContexts\Mail\MailChecker; /** - * Class MailContext - * - * @package Troopers\BehatContexts\BehatContexts\Context + * Class MailContext. */ class MailContext extends RawMinkContext implements Context { protected $kernel; - /** @var MailCollection */ + /** @var MailCollection */ protected $mailCollection; - /** @var MailChecker */ + /** @var MailChecker */ protected $mailChecker; /** @@ -50,6 +47,7 @@ public function iShouldHaveTheEmailWith($event, TableNode $table) /** * @Given /^I follow the link "([^"]*)" for email ([^"]*) with:$/ + * * @param $link * @param $event * @param \Behat\Gherkin\Node\TableNode $table diff --git a/src/Troopers/BehatContexts/DependencyInjection/Compiler/AliasEntityPass.php b/src/Troopers/BehatContexts/DependencyInjection/Compiler/AliasEntityPass.php index 031694a..5d148cb 100644 --- a/src/Troopers/BehatContexts/DependencyInjection/Compiler/AliasEntityPass.php +++ b/src/Troopers/BehatContexts/DependencyInjection/Compiler/AliasEntityPass.php @@ -6,29 +6,28 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; -use Troopers\BehatContexts\Doctrine\EntityHydrator AS TroopersEntityHydrator; +use Troopers\BehatContexts\Doctrine\EntityHydrator as TroopersEntityHydrator; /** - * Pass to permit to alias entity + * Pass to permit to alias entity. */ class AliasEntityPass implements CompilerPassInterface { /** - * use TroopersEntityHydrator to replace friendly.entity.hydrator + * use TroopersEntityHydrator to replace friendly.entity.hydrator. + * * @param ContainerBuilder $container + * * @throws ExtensionInitializationException * @throws ServiceNotFoundException */ public function process(ContainerBuilder $container) { - if($container->hasDefinition('friendly.entity.hydrator')) - { + if ($container->hasDefinition('friendly.entity.hydrator')) { $definition = $container->getDefinition('friendly.entity.hydrator'); $definition->setClass(TroopersEntityHydrator::class); - }else{ + } else { throw new ExtensionInitializationException('Missing extension Knp\FriendlyContexts\Extension', 'Knp\FriendlyContexts\Extension'); } - - } -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/DependencyInjection/Compiler/ContentValidatorChain.php b/src/Troopers/BehatContexts/DependencyInjection/Compiler/ContentValidatorChain.php index a7604d2..9356d85 100644 --- a/src/Troopers/BehatContexts/DependencyInjection/Compiler/ContentValidatorChain.php +++ b/src/Troopers/BehatContexts/DependencyInjection/Compiler/ContentValidatorChain.php @@ -1,15 +1,15 @@ contentValidators)) - { + if (!array_key_exists($key, $this->contentValidators)) { throw new ContentValidatorException(sprintf('Undefined ContentValidator for %s key', $key)); } + return $this->contentValidators[$key]; } /** * @param \Troopers\BehatContexts\ContentValidator\ContentValidatorInterface $contentValidator * @param $key - * */ public function addContentValidator(ContentValidatorInterface $contentValidator, $key) { $this->contentValidators[$key] = $contentValidator; } - -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/DependencyInjection/Compiler/ContentValidatorCompilerPass.php b/src/Troopers/BehatContexts/DependencyInjection/Compiler/ContentValidatorCompilerPass.php index cd85f28..afcfb8d 100644 --- a/src/Troopers/BehatContexts/DependencyInjection/Compiler/ContentValidatorCompilerPass.php +++ b/src/Troopers/BehatContexts/DependencyInjection/Compiler/ContentValidatorCompilerPass.php @@ -3,16 +3,15 @@ namespace Troopers\BehatContexts\DependencyInjection\Compiler; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; /** - * Class ContentValidatorCompilerPass - * - * @package Troopers\BehatContexts\DependencyInjection\Compiler + * Class ContentValidatorCompilerPass. */ -class ContentValidatorCompilerPass implements CompilerPassInterface{ +class ContentValidatorCompilerPass implements CompilerPassInterface +{ /** * You can modify the container here before it is dumped to PHP code. * @@ -31,15 +30,14 @@ public function process(ContainerBuilder $container) foreach ($taggedServices as $id => $tags) { /** @var array $tags */ foreach ($tags as $attributes) { - if (!array_key_exists('contentType', $attributes)) - { - throw new InvalidConfigurationException(sprintf('Missing contentType attribute for %s', $id)); + if (!array_key_exists('contentType', $attributes)) { + throw new InvalidConfigurationException(sprintf('Missing contentType attribute for %s', $id)); } - $definition->addMethodCall('addContentValidator', array( + $definition->addMethodCall('addContentValidator', [ new Reference($id), - $attributes['contentType'] - )); + $attributes['contentType'], + ]); } } } -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/DependencyInjection/Compiler/ExtendedTableNodePass.php b/src/Troopers/BehatContexts/DependencyInjection/Compiler/ExtendedTableNodePass.php index 6a361bd..865db2f 100644 --- a/src/Troopers/BehatContexts/DependencyInjection/Compiler/ExtendedTableNodePass.php +++ b/src/Troopers/BehatContexts/DependencyInjection/Compiler/ExtendedTableNodePass.php @@ -9,26 +9,25 @@ use Troopers\BehatContexts\Utils\TextFormater; /** - * Pass to permit to alias entity + * Pass to permit to alias entity. */ class ExtendedTableNodePass implements CompilerPassInterface { /** - * use TroopersEntityHydrator to replace friendly.entity.hydrator + * use TroopersEntityHydrator to replace friendly.entity.hydrator. + * * @param ContainerBuilder $container + * * @throws ExtensionInitializationException * @throws ServiceNotFoundException */ public function process(ContainerBuilder $container) { - if($container->hasDefinition('friendly.text.formater')) - { + if ($container->hasDefinition('friendly.text.formater')) { $definition = $container->getDefinition('friendly.text.formater'); $definition->setClass(TextFormater::class); - }else{ + } else { throw new ExtensionInitializationException('Missing extension Knp\FriendlyContexts\Extension', 'Knp\FriendlyContexts\Extension'); } - - } -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/DependencyInjection/Compiler/MailPass.php b/src/Troopers/BehatContexts/DependencyInjection/Compiler/MailPass.php index ec1548d..c38d92d 100644 --- a/src/Troopers/BehatContexts/DependencyInjection/Compiler/MailPass.php +++ b/src/Troopers/BehatContexts/DependencyInjection/Compiler/MailPass.php @@ -10,13 +10,15 @@ use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; /** - * Pass to permit to alias entity + * Pass to permit to alias entity. */ class MailPass implements CompilerPassInterface { /** - * use TroopersEntityHydrator to replace friendly.entity.hydrator + * use TroopersEntityHydrator to replace friendly.entity.hydrator. + * * @param ContainerBuilder $container + * * @throws ExtensionInitializationException * @throws ServiceNotFoundException * @throws InvalidArgumentException @@ -25,10 +27,9 @@ class MailPass implements CompilerPassInterface */ public function process(ContainerBuilder $container) { - if($container->hasDefinition('troopers.behatcontexts.mail.parser')) - { + if ($container->hasDefinition('troopers.behatcontexts.mail.parser')) { $mailParser = $container->get('troopers.behatcontexts.mail.parser'); $mailParser->loadMails(); } } -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/Doctrine/EntityHydrator.php b/src/Troopers/BehatContexts/Doctrine/EntityHydrator.php index 458a67d..1ae1924 100644 --- a/src/Troopers/BehatContexts/Doctrine/EntityHydrator.php +++ b/src/Troopers/BehatContexts/Doctrine/EntityHydrator.php @@ -1,23 +1,26 @@ addCompilerPass(new Compiler\ContentValidatorCompilerPass()); $this->buildParameters('troopers.behatcontexts', $parameters, $config); - foreach ($parameters as $name => $parameter) - { + foreach ($parameters as $name => $parameter) { $container->setParameter($name, $parameter); } - $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/services')); + $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/services')); $loader->load('core.yml'); - - if($config['alias_entity']['enabled']) - { + if ($config['alias_entity']['enabled']) { $container->addCompilerPass(new Compiler\AliasEntityPass()); } $container->addCompilerPass(new Compiler\ExtendedTableNodePass()); - if($config['mails']) - { + if ($config['mails']) { $loader->load('mail.yml'); $container->addCompilerPass(new Compiler\MailPass()); } @@ -65,6 +62,7 @@ public function configure(ArrayNodeDefinition $builder) ->canBeEnabled() ->end() ->arrayNode('mails') + ->prototype('array') ->children() ->scalarNode('path') ->isRequired() @@ -88,8 +86,7 @@ public function configure(ArrayNodeDefinition $builder) ->end() ->end() ->end() - ->end() - ; + ->end(); } /** @@ -131,7 +128,6 @@ protected function arrayHasStringKeys(array $array) { foreach ($array as $key => $value) { if (is_string($key)) { - return true; } } diff --git a/src/Troopers/BehatContexts/Mail/MailChecker.php b/src/Troopers/BehatContexts/Mail/MailChecker.php index 9792403..d587a7a 100644 --- a/src/Troopers/BehatContexts/Mail/MailChecker.php +++ b/src/Troopers/BehatContexts/Mail/MailChecker.php @@ -1,5 +1,7 @@ build($mail, $values); - if(isset($mail['CCI'])) - { + if (isset($mail['CCI'])) { $this->build(array_merge($mail, ['to' => $mail['CCI']]), $values); } } @@ -58,10 +56,11 @@ public function check(array $mail = array(), array $values = array()) * @param $mail * @param $values * - * @return mixed * @throws \Troopers\BehatContexts\ContentValidator\ContentValidatorException * @throws \RuntimeException * @throws \InvalidArgumentException + * + * @return mixed */ private function build(array $mail, array $values) { @@ -77,32 +76,27 @@ private function build(array $mail, array $values) $this->mailConfig['translation']['lastCharacter'] ); - if (count($missingTranslations) > 0) - { + if (count($missingTranslations) > 0) { throw new \InvalidArgumentException( 'Missing translations : '.implode(', ', $missingTranslations) ); - } $message = $this->findMail([ - 'to' => $mailToTest['to'], - 'from' => $mailToTest['from'], - 'subject' => $mailToTest['subject'] + 'to' => $mailToTest['to'], + 'from' => $mailToTest['from'], + 'subject' => $mailToTest['subject'], ]); $content = $this->getContent($message); - if (isset($mailToTest['contents']) && is_array($mailToTest['contents']) && count($mailToTest['contents']) > 0) - { + if (isset($mailToTest['contents']) && is_array($mailToTest['contents']) && count($mailToTest['contents']) > 0) { /** - * @var string $contentValidatorKey + * @var string * @var array $contentsToTest */ - foreach ($mailToTest['contents'] as $contentValidatorKey => $contentsToTest) - { + foreach ($mailToTest['contents'] as $contentValidatorKey => $contentsToTest) { /** @var ContentValidatorInterface $contentValidator */ $contentValidator = $this->contentValidatorChain->getContentValidator($contentValidatorKey); - foreach ($contentsToTest as $value) - { + foreach ($contentsToTest as $value) { $contentValidator->supports($value); $contentValidator->valid($value, $content); } @@ -115,10 +109,12 @@ private function build(array $mail, array $values) /** * @param array $criterias * - * @return \Alex\MailCatcher\Message|null * @throws \InvalidArgumentException + * + * @return \Alex\MailCatcher\Message|null */ - private function findMail(array $criterias){ + private function findMail(array $criterias) + { //get mail with "to", "from" and "subject" @@ -135,8 +131,8 @@ private function findMail(array $criterias){ $recipients .= $recipient->getEmail().' '; } $currentMails[] = json_encode([ - 'to' => trim($recipients), - 'from' => $message->getSender()->getEmail(), + 'to' => trim($recipients), + 'from' => $message->getSender()->getEmail(), 'subject' => $message->getSubject(), ]); } @@ -146,15 +142,17 @@ private function findMail(array $criterias){ ], $currentMails); throw new \InvalidArgumentException(implode("\n", $exceptions)); } + return $message; } /** * @param \Alex\MailCatcher\Message $message * - * @return string * @throws \InvalidArgumentException * @throws \RuntimeException + * + * @return string */ private function getContent(Message $message) { @@ -173,6 +171,7 @@ private function getContent(Message $message) if (true === strpos($content, 'translateToXPath(['link', $link]); $content = $this->build($mail, $values); $crawler = new Crawler($content); $mailLink = $crawler->filterXPath($xpath); + return $mailLink->attr('href'); } -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/Parser/Mail/MailParser.php b/src/Troopers/BehatContexts/Parser/Mail/MailParser.php index 99cc4bb..9d1d87a 100644 --- a/src/Troopers/BehatContexts/Parser/Mail/MailParser.php +++ b/src/Troopers/BehatContexts/Parser/Mail/MailParser.php @@ -7,10 +7,10 @@ use Troopers\BehatContexts\Component\ConfigReader; /** - * Class MailParser - * @package Troopers\BehatContexts\Parser\Mail + * Class MailParser. */ -class MailParser { +class MailParser +{ private $reader; private $mailsConfig; private $mailCollection; @@ -25,18 +25,14 @@ class MailParser { public function __construct(ConfigReader $reader, MailCollection $mailCollection, array $mailsConfig) { $this->reader = $reader; - $this->mailsConfig= $mailsConfig; + $this->mailsConfig = $mailsConfig; $this->mailCollection = $mailCollection; } - /** - * - */ public function loadMails() { $config = $this->reader->load($this->mailsConfig['path'], $this->mailsConfig['key']); - foreach ($config as $eventName => $emailConfig) - { + foreach ($config as $eventName => $emailConfig) { $this->validMailConfig($eventName, $emailConfig); $this->mailCollection->set($eventName, $emailConfig); } @@ -49,28 +45,23 @@ public function loadMails() private function validMailConfig($event, $config) { $exceptions = []; - if(!isset($config['to'])) - { + if (!isset($config['to'])) { $exceptions[] = 'Missing configuration for "to"'; - }elseif(!$config['to']){ + } elseif (!$config['to']) { $exceptions[] = 'Value not found for "to"'; } - if(!isset($config['from'])) - { + if (!isset($config['from'])) { $exceptions[] = 'Missing configuration for "from"'; - }elseif(!$config['from']){ + } elseif (!$config['from']) { $exceptions[] = 'Value not found for "from"'; } - if(!isset($config['subject'])) - { + if (!isset($config['subject'])) { $exceptions[] = 'Missing configuration for "subject"'; - }elseif(!$config['subject']){ + } elseif (!$config['subject']) { $exceptions[] = 'Value not found for "subject"'; } - if(count($exceptions) > 0) - { + if (count($exceptions) > 0) { throw new InvalidConfigurationException(sprintf('Invalid for event Configuration "%s" : %s', $event, implode(', ', $exceptions))); } } - -} \ No newline at end of file +} diff --git a/src/Troopers/BehatContexts/Tests/Component/ConfigReaderTest.php b/src/Troopers/BehatContexts/Tests/Component/ConfigReaderTest.php index ac7505e..331d26e 100644 --- a/src/Troopers/BehatContexts/Tests/Component/ConfigReaderTest.php +++ b/src/Troopers/BehatContexts/Tests/Component/ConfigReaderTest.php @@ -1,16 +1,15 @@ assertEquals($parsedConfig, $expected); } - /** - * - */ public function testReadMultiplesFilesConfig() { $configs = [ [ 'test_key' => [ 'arg1' => [ - 'test' => 'value' - ] - ] + 'test' => 'value', + ], + ], ], [ 'test_key' => [ 'arg2' => [ - 'test2' => 'value2' - ] - ] - ] + 'test2' => 'value2', + ], + ], + ], ]; - foreach ($configs as $config) - { + foreach ($configs as $config) { $this->generateConfigFile($config); } $configReader = new ConfigReader($this->driver->url()); @@ -87,14 +82,15 @@ public function testReadMultiplesFilesConfig() $this->assertEquals($parsedConfig, [ 'arg1' => [ - 'test' => 'value' + 'test' => 'value', ], 'arg2' => [ - 'test2' => 'value2' - ] + 'test2' => 'value2', + ], ] ); } + public function testNoConfigFileFound() { $this->expectException(FileNotFoundException::class); @@ -103,31 +99,27 @@ public function testNoConfigFileFound() ); $configReader = new ConfigReader($this->driver->url()); $configReader->load($this->directoryName, 'test_key'); - } - /** - **/ public function testInvalidConfigFile() { $configs = [ [ 'test_key' => [ 'arg1' => [ - 'test' => 'value' - ] - ] + 'test' => 'value', + ], + ], ], [ 'test_key' => [ 'arg1' => [ - 'test2' => 'value2' - ] - ] - ] + 'test2' => 'value2', + ], + ], + ], ]; - foreach ($configs as $config) - { + foreach ($configs as $config) { $this->generateConfigFile($config); } $configReader = new ConfigReader($this->driver->url()); @@ -138,21 +130,18 @@ public function testInvalidConfigFile() $configReader->load($this->directoryName, 'test_key'); } - /** - */ public function testNoConfigDefinedInFile() { $configs = [ [ 'test_key' => [ 'arg1' => [ - 'test' => 'value' - ] - ] - ] + 'test' => 'value', + ], + ], + ], ]; - foreach ($configs as $config) - { + foreach ($configs as $config) { $this->generateConfigFile($config); } $configReader = new ConfigReader($this->driver->url()); @@ -162,7 +151,6 @@ public function testNoConfigDefinedInFile() '/The file located in (\S*).yml has no config value "wrong_key"$/' ); $configReader->load($this->directoryName, 'wrong_key'); - } /** @@ -171,17 +159,16 @@ public function testNoConfigDefinedInFile() */ private function generateConfigFile($data = null, $filename = '') { - if($filename === '') - { - $filename = md5(microtime()) . '.yml'; + if ($filename === '') { + $filename = md5(microtime()).'.yml'; } - if(!$this->driver->hasChild($filename)) - { + if (!$this->driver->hasChild($filename)) { $file = vfsStream::newFile($filename); $file->setContent(Yaml::dump($data)); $this->configDirectory->addChild($file); } } + public function oneFileConfigProvider() { return [ @@ -189,17 +176,16 @@ public function oneFileConfigProvider() [ 'test_key' => [ 'arg1' => [ - 'test' => 'value' - ] - ] + 'test' => 'value', + ], + ], ], [ 'arg1' => [ - 'test' => 'value' - ] + 'test' => 'value', + ], ], ], ]; } - } diff --git a/src/Troopers/BehatContexts/Tests/Component/ConfigTranslatorTest.php b/src/Troopers/BehatContexts/Tests/Component/ConfigTranslatorTest.php index 6aa3045..f57e0b0 100644 --- a/src/Troopers/BehatContexts/Tests/Component/ConfigTranslatorTest.php +++ b/src/Troopers/BehatContexts/Tests/Component/ConfigTranslatorTest.php @@ -5,9 +5,7 @@ use Troopers\BehatContexts\Component\ConfigTranslator; /** - * Class ConfigTranslatorTest - * - * @package Troopers\BehatContexts\Tests\Component + * Class ConfigTranslatorTest. */ class ConfigTranslatorTest extends \PHPUnit_Framework_TestCase { @@ -30,15 +28,14 @@ public function testRebuildTranslationKeys() $configTranslator = new ConfigTranslator(); $parameters = [ ['key1', 'value1'], - ['key2', 'value2'] + ['key2', 'value2'], ]; $configTranslator->rebuildTranslationKeys($parameters, '%', '%'); $this->assertEquals( [ '%key1%' => 'value1', - '%key2%' => 'value2' - ] - , $parameters); + '%key2%' => 'value2', + ], $parameters); } /** @@ -49,7 +46,7 @@ public function testInvalidRebuildTranslationKeys() $configTranslator = new ConfigTranslator(); $parameters = [ ['key1', 'value1'], - ['key2'] + ['key2'], ]; $configTranslator->rebuildTranslationKeys($parameters, '%', '%'); } @@ -59,10 +56,10 @@ public function testGetMissingTranslations() $configTranslator = new ConfigTranslator(); $missingTranslations = $configTranslator->getMissingTranslations( [ - 'test' => 'va%lue', + 'test' => 'va%lue', 'test2' => [ - 'test3' => 'value2' - ] + 'test3' => 'value2', + ], ], '%', '%' @@ -70,11 +67,11 @@ public function testGetMissingTranslations() $this->assertEquals([], $missingTranslations); $missingTranslations = $configTranslator->getMissingTranslations( [ - 'test' => '%val%ue', + 'test' => '%val%ue', 'test2' => [ - 'test3' => '%val%ue2' + 'test3' => '%val%ue2', ], - 'test4' => 'bla%bla%bla' + 'test4' => 'bla%bla%bla', ], '%', '%' @@ -85,66 +82,61 @@ public function testGetMissingTranslations() public function translationsProvider() { return [ - ['simple translation' => - [ + ['simple translation' => [ 'index' => [ - 'test' => '%value%' - ] + 'test' => '%value%', + ], ], ['%value%' => 'phpunit'], [ 'index' => [ - 'test' => 'phpunit' - ] - ] + 'test' => 'phpunit', + ], + ], ], - ['recursive translation' => - [ + ['recursive translation' => [ 'index' => [ 'test' => [ - 'test_test' => '%value%' - ] - ] + 'test_test' => '%value%', + ], + ], ], ['%value%' => 'phpunit'], [ 'index' => [ 'test' => [ - 'test_test' => 'phpunit' - ] - ] + 'test_test' => 'phpunit', + ], + ], ], ], - ['multiple translation' => - [ + ['multiple translation' => [ 'index' => [ - 'test' => '%value%', - 'test2' => '%value2%' - ] + 'test' => '%value%', + 'test2' => '%value2%', + ], ], ['%value%' => 'first', '%value2%' => 'second'], [ 'index' => [ - 'test' => 'first', - 'test2' => 'second' - ] - ] + 'test' => 'first', + 'test2' => 'second', + ], + ], ], - ['mixed translation' => - [ + ['mixed translation' => [ 'index' => [ - 'test' => 'tetsu jssfdsf o,%value% sfcsibn49451' - ] + 'test' => 'tetsu jssfdsf o,%value% sfcsibn49451', + ], ], ['%value%' => 'phpunit'], [ 'index' => [ - 'test' => 'tetsu jssfdsf o,phpunit sfcsibn49451' - ] - ] + 'test' => 'tetsu jssfdsf o,phpunit sfcsibn49451', + ], + ], ], - ]; } } diff --git a/src/Troopers/BehatContexts/Tests/Mail/MailCheckerTest.php b/src/Troopers/BehatContexts/Tests/Mail/MailCheckerTest.php index 4e764e4..b22f8d1 100644 --- a/src/Troopers/BehatContexts/Tests/Mail/MailCheckerTest.php +++ b/src/Troopers/BehatContexts/Tests/Mail/MailCheckerTest.php @@ -3,12 +3,11 @@ * Created by PhpStorm. * User: charlie * Date: 03/01/2017 - * Time: 17:24 + * Time: 17:24. */ namespace Troopers\BehatContexts\Tests\Mail; - use Alex\MailCatcher\Tests\AbstractTest; use Troopers\BehatContexts\Component\ConfigTranslator; use Troopers\BehatContexts\ContentValidator\StringValidator; @@ -17,35 +16,30 @@ class MailCheckerTest extends AbstractTest { - - /** - * - */ public function testBuild() { $message = \Swift_Message::newInstance() ->setSubject('Mail to test') - ->setFrom('sender@sender.sender' ) + ->setFrom('sender@sender.sender') ->setTo('to@to.to') - ->setBody('Content') - ; + ->setBody('Content'); $this->sendMessage($message); $mailChecker = $this->getMailChecker(); $this->invokeMethod($mailChecker, 'build', [ [ - 'to' => '%user%', - 'from' => 'sender@sender.sender', - 'subject' => 'Mail to %context%', + 'to' => '%user%', + 'from' => 'sender@sender.sender', + 'subject' => 'Mail to %context%', 'contents' => [ - 'strings' => ['Content'] - ] + 'strings' => ['Content'], + ], ], [ ['user', 'to@to.to'], ['context', 'test'], - ] + ], ]); } @@ -53,10 +47,9 @@ public function testBuildWithMissingTranslations() { $message = \Swift_Message::newInstance() ->setSubject('Mail to test') - ->setFrom('sender@sender.sender' ) + ->setFrom('sender@sender.sender') ->setTo('to@to.to') - ->setBody('Content') - ; + ->setBody('Content'); $this->sendMessage($message); $this->expectException(\InvalidArgumentException::class); @@ -66,28 +59,26 @@ public function testBuildWithMissingTranslations() $this->invokeMethod($mailChecker, 'build', [ [ - 'to' => '%user%', - 'from' => 'sender@sender.sender', - 'subject' => 'Mail to %context%', + 'to' => '%user%', + 'from' => 'sender@sender.sender', + 'subject' => 'Mail to %context%', 'contents' => [ - 'strings' => ['Wrong Content'] - ] + 'strings' => ['Wrong Content'], + ], ], [ - ['user', 'to@to.to'] - ] + ['user', 'to@to.to'], + ], ]); - } public function testMissingBuildContent() { $message = \Swift_Message::newInstance() ->setSubject('Mail to test') - ->setFrom('sender@sender.sender' ) + ->setFrom('sender@sender.sender') ->setTo('to@to.to') - ->setBody('Content') - ; + ->setBody('Content'); $this->sendMessage($message); $this->expectException(\InvalidArgumentException::class); @@ -96,29 +87,27 @@ public function testMissingBuildContent() $this->invokeMethod($mailChecker, 'build', [ [ - 'to' => '%user%', - 'from' => 'sender@sender.sender', - 'subject' => 'Mail to %context%', + 'to' => '%user%', + 'from' => 'sender@sender.sender', + 'subject' => 'Mail to %context%', 'contents' => [ - 'strings' => ['Wrong Content'] - ] + 'strings' => ['Wrong Content'], + ], ], [ ['user', 'to@to.to'], - ['context', 'test'] - ] + ['context', 'test'], + ], ]); - } public function testFindMails() { $message = \Swift_Message::newInstance() ->setSubject('Mail to test') - ->setFrom('sender@sender.sender' ) + ->setFrom('sender@sender.sender') ->setTo('to@to.to') - ->setBody('Content') - ; + ->setBody('Content'); $this->sendMessage($message); $mailChecker = $this->getMailChecker(); @@ -126,10 +115,10 @@ public function testFindMails() $this->invokeMethod($mailChecker, 'findMail', [ [ - 'to' => 'to@to.to', - 'from' => 'sender@sender.sender', + 'to' => 'to@to.to', + 'from' => 'sender@sender.sender', 'subject' => 'Mail to test', - ] + ], ]) ); } @@ -138,10 +127,9 @@ public function testCannotFindMails() { $message = \Swift_Message::newInstance() ->setSubject('Mail to test') - ->setFrom('sender@sender.sender' ) + ->setFrom('sender@sender.sender') ->setTo('to@to.to') - ->setBody('Content') - ; + ->setBody('Content'); $this->sendMessage($message); $mailChecker = $this->getMailChecker(); @@ -153,10 +141,10 @@ public function testCannotFindMails() $this->invokeMethod($mailChecker, 'findMail', [ [ - 'to' => 'to@to.to', - 'from' => 'wrongsender@sender.sender', + 'to' => 'to@to.to', + 'from' => 'wrongsender@sender.sender', 'subject' => 'Mail to test', - ] + ], ]); } @@ -172,17 +160,15 @@ public function testGetLink(\Swift_Message $message, $link, $href) $this->sendMessage($message); $mailChecker = $this->getMailChecker(); $this->assertEquals( - $href - ,$mailChecker->getLink( + $href, $mailChecker->getLink( [ - 'to' => 'to@to.to', - 'from' => 'sender@sender.sender', - 'subject' => 'Mail to test', - 'contents' => [] + 'to' => 'to@to.to', + 'from' => 'sender@sender.sender', + 'subject' => 'Mail to test', + 'contents' => [], ], [], $link ) ); - } public function swiftMessageWithLinkProvider() @@ -192,25 +178,25 @@ public function swiftMessageWithLinkProvider() [ \Swift_Message::newInstance() ->setSubject('Mail to test') - ->setFrom('sender@sender.sender' ) + ->setFrom('sender@sender.sender') ->setTo('to@to.to') ->setBody('

Content \n Test Link

', 'text/html'), 'Test Link', - 'link1' + 'link1', ], [ \Swift_Message::newInstance() ->setSubject('Mail to test') - ->setFrom('sender@sender.sender' ) + ->setFrom('sender@sender.sender') ->setTo('to@to.to') ->setBody('

Content \n Test Link

', 'text/html'), 'test_link', - 'link2' + 'link2', ], ]; } - private function invokeMethod(&$object, $methodName, array $parameters = array()) + private function invokeMethod(&$object, $methodName, array $parameters = []) { $reflection = new \ReflectionClass(get_class($object)); $method = $reflection->getMethod($methodName); @@ -231,11 +217,12 @@ private function getMailChecker() $this->returnValueMap( [ [ - 'strings', new StringValidator() - ] + 'strings', new StringValidator(), + ], ] ) ); + return new MailChecker( new ConfigTranslator(), $mailConfig, diff --git a/src/Troopers/BehatContexts/Tests/Utils/TextFormaterTest.php b/src/Troopers/BehatContexts/Tests/Utils/TextFormaterTest.php index a348e9f..67f1209 100644 --- a/src/Troopers/BehatContexts/Tests/Utils/TextFormaterTest.php +++ b/src/Troopers/BehatContexts/Tests/Utils/TextFormaterTest.php @@ -2,7 +2,6 @@ namespace Troopers\BehatContexts\Tests\Utils; - use Troopers\BehatContexts\Utils\TextFormater; class TextFormaterTest extends \PHPUnit_Framework_TestCase @@ -18,6 +17,7 @@ public function testListToArray($list, $expected) $actual = $textFormater->listToArray($list); $this->assertEquals($expected, $actual); } + public function listToArrayProvider() { return [ @@ -25,18 +25,19 @@ public function listToArrayProvider() 'test, test2', [ 'test', - 'test2' - ] + 'test2', + ], ], [ 'test : value, test2: value2', [ - 'test' => 'value', - 'test2' => 'value2' - ] - ] + 'test' => 'value', + 'test2' => 'value2', + ], + ], ]; } + public function testInvalidListToArray() { $textFormater = new TextFormater(); diff --git a/src/Troopers/BehatContexts/Utils/TextFormater.php b/src/Troopers/BehatContexts/Utils/TextFormater.php index 01e6dfb..b2def04 100644 --- a/src/Troopers/BehatContexts/Utils/TextFormater.php +++ b/src/Troopers/BehatContexts/Utils/TextFormater.php @@ -2,24 +2,26 @@ namespace Troopers\BehatContexts\Utils; -use Knp\FriendlyContexts\Utils\TextFormater AS BaseTextFormater; - -class TextFormater extends BaseTextFormater { +use Knp\FriendlyContexts\Utils\TextFormater as BaseTextFormater; +class TextFormater extends BaseTextFormater +{ /** * @param $list - * @param array $delimiters + * @param array $delimiters * @param string $parser * @param string $link - * @return array + * * @throws \InvalidArgumentException * @throws \UnexpectedValueException + * + * @return array */ - public function listToArray($list, $delimiters = [', ', ' and '], $parser = "#||#", $link = ':') + public function listToArray($list, $delimiters = [', ', ' and '], $parser = '#||#', $link = ':') { - $list = str_replace('"', '', $list); + $list = str_replace('"', '', $list); foreach ($delimiters as $delimiter) { - $list = str_replace($delimiter, $parser, $list); + $list = str_replace($delimiter, $parser, $list); } if (!is_string($list)) { throw new \InvalidArgumentException(sprintf('The list must be a string, not a "%s" element', gettype($list))); @@ -30,30 +32,33 @@ public function listToArray($list, $delimiters = [', ', ' and '], $parser = "#|| } $parts = array_map('trim', $parts); $parts = array_filter($parts, 'strlen'); + return $parts; } /** * @param array $parts * @param $link - * @return array + * * @throws \UnexpectedValueException + * + * @return array */ - protected function orderKeyValueTable(array $parts, $link) { + protected function orderKeyValueTable(array $parts, $link) + { $keyValueTable = []; foreach ($parts as $part) { $part = explode($link, $part); - if (count($part)%2 === 0) { + if (count($part) % 2 === 0) { $iiMax = count($part); for ($ii = 0; $ii < $iiMax; $ii += 2) { - $keyValueTable[trim($part[$ii])] = $part[$ii+1]; + $keyValueTable[trim($part[$ii])] = $part[$ii + 1]; } - } else { throw new \UnexpectedValueException('Key without value in list'); } } + return $keyValueTable; } - -} \ No newline at end of file +}