Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 avoid error when not setting/using MailContext #15

Merged
merged 2 commits into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Troopers/BehatContexts/Collection/MailCollection.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

namespace Troopers\BehatContexts\Collection;

use Doctrine\Common\Collections\ArrayCollection;

/**
* Class MailCollection
*
* @package Troopers\BehatContexts\Collection
* Class MailCollection.
*/
class MailCollection extends ArrayCollection {

}
class MailCollection extends ArrayCollection
{
}
22 changes: 11 additions & 11 deletions src/Troopers/BehatContexts/Component/ConfigReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\Yaml\Yaml;

class ConfigReader {
class ConfigReader
{
private $rootDir;

/**
* ConfigReader constructor.
*
* @param $rootDir
*/
public function __construct($rootDir)
Expand All @@ -23,20 +25,20 @@ public function __construct($rootDir)
* @param $path
* @param $key
*
* @return array
* @throws \RuntimeException
* @throws \Symfony\Component\Yaml\Exception\ParseException
* @throws \InvalidArgumentException
* @throws \Symfony\Component\Filesystem\Exception\FileNotFoundException
* @throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*
* @return array
*/
public function load($path, $key)
{
$finder = new Finder();
$finder->files()->in($this->rootDir.'/'.$path);
$result = [];
if(!$finder->count())
{
if (!$finder->count()) {
throw new FileNotFoundException('No configuration found');
}
// read yaml config files
Expand All @@ -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;
}
}
}
21 changes: 10 additions & 11 deletions src/Troopers/BehatContexts/Component/ConfigTranslator.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?php

namespace Troopers\BehatContexts\Component;

/**
* Class ConfigTranslator
*
* @package Troopers\BehatContexts\Component
* Class ConfigTranslator.
*/
class ConfigTranslator {
class ConfigTranslator
{
/**
* @param array $config
*
* @return array
*/
public function getMissingTranslations(array $config = array(), $firstCharacter, $lastCharacter)
public function getMissingTranslations(array $config, $firstCharacter, $lastCharacter)
{

$arguments = [];
//find string that need to be replaced
foreach ($config as $property) {
Expand All @@ -37,7 +36,7 @@ public function getMissingTranslations(array $config = array(), $firstCharacter,
*
* @return array
*/
public function translate(array $config = array(), array $parameters = array())
public function translate(array $config = [], array $parameters = [])
{
$keys = array_keys($parameters);
$values = array_values($parameters);
Expand All @@ -54,21 +53,21 @@ public function translate(array $config = array(), array $parameters = array())
}

/**
* @param array $parameters ['translationKey' => $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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace Troopers\BehatContexts\ContentValidator;


/**
* class ContentValidatorException
* class ContentValidatorException.
*/
class ContentValidatorException extends \Exception
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace Troopers\BehatContexts\ContentValidator;

interface ContentValidatorInterface {
interface ContentValidatorInterface
{
/**
* @param mixed $value
* @param string $content
Expand All @@ -13,7 +14,6 @@ public function valid($value, $content = '');

/**
* @param mixed $value
*
*/
public function supports($value);
}
}
11 changes: 6 additions & 5 deletions src/Troopers/BehatContexts/ContentValidator/StringValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace Troopers\BehatContexts\ContentValidator;

class StringValidator implements ContentValidatorInterface {
class StringValidator implements ContentValidatorInterface
{
/**
* @param mixed $value
*
* @throws \Troopers\BehatContexts\ContentValidator\ContentValidatorException
*/
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)));
}
}
Expand All @@ -20,13 +20,14 @@ public function supports($value)
* @param string $value
* @param string $content
*
* @return mixed
* @throws \InvalidArgumentException
*
* @return mixed
*/
public function valid($value, $content = '')
{
if (false === strpos($content, $value)) {
throw new \InvalidArgumentException(sprintf("Unable to find text \"%s\" in current message:\n%s", $value, $content));
}
}
}
}
26 changes: 12 additions & 14 deletions src/Troopers/BehatContexts/ContentValidator/TableValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@

use DOMDocument;

class TableValidator implements ContentValidatorInterface {
class TableValidator implements ContentValidatorInterface
{
/**
* @param mixed $value
*
* @throws \Troopers\BehatContexts\ContentValidator\ContentValidatorException
*/
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)));
}
}
}
Expand All @@ -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) {
Expand All @@ -55,4 +53,4 @@ public function valid( $value = [], $content = '')
}
}
}
}
}
21 changes: 10 additions & 11 deletions src/Troopers/BehatContexts/Context/ExtendedAliceContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -33,10 +31,12 @@ private function getPersistableClasses()

return $persistable;
}

/**
* @param $loader
* @param $fixtures
* @param $files
*
* @throws OptimisticLockException
* @throws ORMInvalidArgumentException
*/
Expand All @@ -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);
}
Expand All @@ -61,4 +60,4 @@ protected function loadFixtures($loader, $fixtures, $files)
}
}
}
}
}
15 changes: 8 additions & 7 deletions src/Troopers/BehatContexts/Context/ExtendedEntityContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -38,4 +39,4 @@ public function beforeScenario($event)
}
}
}
}
}
Loading