diff --git a/src/MicheleAngioni/Support/Helpers.php b/src/MicheleAngioni/Support/Helpers.php index dff7aa0..89b27e5 100644 --- a/src/MicheleAngioni/Support/Helpers.php +++ b/src/MicheleAngioni/Support/Helpers.php @@ -7,321 +7,321 @@ class Helpers { - /** - * Check if input value is integer: return true on success, false otherwise. - * int(4), string '4', float(4), 0x7FFFFFFF return true - * int(4.1), string '1.2', string '0x8', float(1.2) return false. - * min and max allowed values can be inserted - * - * @param int $int - * @param bool|int $min = false - * @param bool|int $max = false - * - * @return bool - */ - static function isInt($int, $min = false, $max = false) - { - if (is_object($int) || is_array($int)) { - return false; - } - - if ($min !== false) { - if (is_numeric($min) && (int)$min == $min) { - if ($int < $min) { - return false; - } - } else { - return false; - } - } - - if ($max !== false) { - if (is_numeric($max) && (int)$max == $max) { - if ($int > $max) { - return false; - } - } else { - return false; - } - } - - return is_numeric($int) && (int)$int == $int; - } - - /** - * Return a random value out of an array - * - * @param array $array - * - * @return mixed - */ - static function randInArray(array $array) - { - return $array[mt_rand(0, count($array) - 1)]; - } - - /** - * Check date validity. Return true on success or false on failure. - * - * @param string $date - * @param string $format = 'Y-m-d' - * - * @return bool - */ - static function checkDate($date, $format = 'Y-m-d') - { - $d = DateTime::createFromFormat($format, $date); - - return $d && $d->format($format) == $date; - } - - /** - * Check datetime 'Y-m-d H:i:s' validity. Returns true if ok or false if it fails. - * - * @param string $datetime - * - * @return bool - */ - static function checkDatetime($datetime) - { - $format = 'Y-m-d H:i:s'; - - $d = DateTime::createFromFormat($format, $datetime); - - return $d && $d->format($format) == $datetime; - } - - /** - * Split two 'Y-m-d'-format dates into an array of dates. Returns false on failure. - * $first_date must be < than $second_date - * Third optional parameter indicates max days difference allowed (0 = no limits). - * - * @param string $firstDate - * @param string $secondDate - * @param int $maxDifference = 0 - * - * @return array - */ - static function splitDates($firstDate, $secondDate, $maxDifference = 0) - { - if (!self::checkDate($firstDate) || !self::checkDate($secondDate)) { - return false; - } - - if (!self::isInt($maxDifference, 0)) { - return false; - } - - $date1 = new DateTime($firstDate); - $date2 = new DateTime($secondDate); - $interval = $date1->diff($date2, false); - - if ((int)$interval->format('%R%a') < 0) { - return false; - } - - if ($maxDifference != 0) { - if ((int)$interval->format('%R%a') > $maxDifference) { - return false; - } - } - - list($year, $month, $day) = array_pad(explode("-", $firstDate), 3, 0); - - $i = 0; - $newDate = $firstDate; - $dates = []; - - while ($newDate <= $secondDate) { - $dates[] = $newDate; - $i++; - $newDate = date("Y-m-d", mktime(0, 0, 0, $month, $day + $i, $year)); - } - - return $dates; - } - - /** - * Return the number of days between the two input 'Y-m-d' or 'Y-m-d X' (X is some text) dates. - * $date2 must be >= than $date1. - * Returns false on failure. - * - * @param string $date1 - * @param string $date2 - * - * @return int - */ - static function daysBetweenDates($date1, $date2) - { - // If input dates have datetime 'Y-m-d X' format, take only the date part - list($d1) = array_pad(explode(' ', $date1), 1, 0); - list($d2) = array_pad(explode(' ', $date2), 1, 0); - - if (!self::checkDate($d1) || !self::checkDate($d2)) { - return false; - } - - if (!($dates = self::splitDates($d1, $d2))) { - return false; - } - - return (count($dates) - 1); - } - - /** - * Compare $date with $referenceDate. Return true if $date is more recent, false otherwise (included if the two dates are identical). - * - * @param string $date - * @param string $referenceDate - * - * @return bool - */ - static function compareDates($date, $referenceDate) - { - $dateTimestamp = strtotime($date); - $referenceDateTimestamp = strtotime($referenceDate); - - if ($dateTimestamp > $referenceDateTimestamp) { - return true; - } else { - return false; - } - } - - /** - * Split a Collection into groups of equal numbers. $groupsNumber must be a multiplier of 2. - * - * @param Collection $collection - * @param int $groupsNumber = 2 - * - * @throws InvalidArgumentException - * - * @return array - */ - static function divideCollectionIntoGroups(Collection $collection, $groupsNumber = 2) - { - if (!(Helpers::isInt($groupsNumber, 2) && !($groupsNumber % 2))) { - return false; - } - - $elementsPerGroup = (int)ceil(count($collection) / $groupsNumber); - - $newCollection = new Collection([]); - - for ($i = 0; $i <= $groupsNumber - 1; $i++) { - $newCollection[$i] = $collection->slice($i * $elementsPerGroup, $elementsPerGroup); - } - - return $newCollection; - } - - - // <<<--- DATE TIME METHODS --->>> - - /* + /** + * Check if input value is integer: return true on success, false otherwise. + * int(4), string '4', float(4), 0x7FFFFFFF return true + * int(4.1), string '1.2', string '0x8', float(1.2) return false. + * min and max allowed values can be inserted + * + * @param int $int + * @param bool|int $min = false + * @param bool|int $max = false + * + * @return bool + */ + static function isInt($int, $min = false, $max = false) + { + if (is_object($int) || is_array($int)) { + return false; + } + + if ($min !== false) { + if (is_numeric($min) && (int)$min == $min) { + if ($int < $min) { + return false; + } + } else { + return false; + } + } + + if ($max !== false) { + if (is_numeric($max) && (int)$max == $max) { + if ($int > $max) { + return false; + } + } else { + return false; + } + } + + return is_numeric($int) && (int)$int == $int; + } + + /** + * Return a random value out of an array + * + * @param array $array + * + * @return mixed + */ + static function randInArray(array $array) + { + return $array[mt_rand(0, count($array) - 1)]; + } + + /** + * Check date validity. Return true on success or false on failure. + * + * @param string $date + * @param string $format = 'Y-m-d' + * + * @return bool + */ + static function checkDate($date, $format = 'Y-m-d') + { + $d = DateTime::createFromFormat($format, $date); + + return $d && $d->format($format) == $date; + } + + /** + * Check datetime 'Y-m-d H:i:s' validity. Returns true if ok or false if it fails. + * + * @param string $datetime + * + * @return bool + */ + static function checkDatetime($datetime) + { + $format = 'Y-m-d H:i:s'; + + $d = DateTime::createFromFormat($format, $datetime); + + return $d && $d->format($format) == $datetime; + } + + /** + * Split two 'Y-m-d'-format dates into an array of dates. Returns false on failure. + * $first_date must be < than $second_date + * Third optional parameter indicates max days difference allowed (0 = no limits). + * + * @param string $firstDate + * @param string $secondDate + * @param int $maxDifference = 0 + * + * @return array + */ + static function splitDates($firstDate, $secondDate, $maxDifference = 0) + { + if (!self::checkDate($firstDate) || !self::checkDate($secondDate)) { + return false; + } + + if (!self::isInt($maxDifference, 0)) { + return false; + } + + $date1 = new DateTime($firstDate); + $date2 = new DateTime($secondDate); + $interval = $date1->diff($date2, false); + + if ((int)$interval->format('%R%a') < 0) { + return false; + } + + if ($maxDifference != 0) { + if ((int)$interval->format('%R%a') > $maxDifference) { + return false; + } + } + + list($year, $month, $day) = array_pad(explode("-", $firstDate), 3, 0); + + $i = 0; + $newDate = $firstDate; + $dates = []; + + while ($newDate <= $secondDate) { + $dates[] = $newDate; + $i++; + $newDate = date("Y-m-d", mktime(0, 0, 0, $month, $day + $i, $year)); + } + + return $dates; + } + + /** + * Return the number of days between the two input 'Y-m-d' or 'Y-m-d X' (X is some text) dates. + * $date2 must be >= than $date1. + * Returns false on failure. + * + * @param string $date1 + * @param string $date2 + * + * @return int + */ + static function daysBetweenDates($date1, $date2) + { + // If input dates have datetime 'Y-m-d X' format, take only the date part + list($d1) = array_pad(explode(' ', $date1), 1, 0); + list($d2) = array_pad(explode(' ', $date2), 1, 0); + + if (!self::checkDate($d1) || !self::checkDate($d2)) { + return false; + } + + if (!($dates = self::splitDates($d1, $d2))) { + return false; + } + + return (count($dates) - 1); + } + + /** + * Compare $date with $referenceDate. Return true if $date is more recent, false otherwise (included if the two dates are identical). + * + * @param string $date + * @param string $referenceDate + * + * @return bool + */ + static function compareDates($date, $referenceDate) + { + $dateTimestamp = strtotime($date); + $referenceDateTimestamp = strtotime($referenceDate); + + if ($dateTimestamp > $referenceDateTimestamp) { + return true; + } else { + return false; + } + } + + /** + * Split a Collection into groups of equal numbers. $groupsNumber must be a multiplier of 2. + * + * @param Collection $collection + * @param int $groupsNumber = 2 + * + * @throws InvalidArgumentException + * + * @return array + */ + static function divideCollectionIntoGroups(Collection $collection, $groupsNumber = 2) + { + if (!(Helpers::isInt($groupsNumber, 2) && !($groupsNumber % 2))) { + return false; + } + + $elementsPerGroup = (int)ceil(count($collection) / $groupsNumber); + + $newCollection = new Collection([]); + + for ($i = 0; $i <= $groupsNumber - 1; $i++) { + $newCollection[$i] = $collection->slice($i * $elementsPerGroup, $elementsPerGroup); + } + + return $newCollection; + } + + + // <<<--- DATE TIME METHODS --->>> + + /* * These DateTime methods are thought in order to allow Date / Time mocking in tests and other useful uses. */ - /** - * Return today's day. - * - * @return string - */ - function getTodayDay() - { - $datetime = new \DateTime("now"); - - return $datetime->format("D"); - } - - /** - * Return today's day in format Y-m-d. Offset in days. - * Customize $format to receive the wanted date format. - * - * @param int $offset = 0 - * @param string $format = 'Y-m-d' - * - * @return string - */ - function getDate($offset = 0, $format = 'Y-m-d') - { - return date($format, strtotime($offset . ' day')); - } - - /** - * Return today's time in format H:i:s. Offset in minutes. - * Customize $format to receive the wanted time format. - * - * @param int $offset = 0 - * @param string $format = 'H:i:s' - * - * @return string - */ - function getTime($offset = 0, $format = 'H:i:s') - { - return date($format, strtotime($offset . ' minutes')); - } - - - // <<<--- PSEUDO-RANDOM NUMBERS METHODS --->>> - - - /** - * Return a random value between input $min and $max values by using the MCRYPT_DEV_URANDOM source. - * N.B. Use only on *nix servers! - * - * @param int $min = 0 - * @param int $max - * - * @return int - */ - static function getRandomValueUrandom($min = 0, $max = 0x7FFFFFFF) - { - if (!self::isInt($min) || !self::isInt($max) || $max < $min || ($max - $min) > 0x7FFFFFFF) { - return false; - } - - $diff = $max - $min; - - $bytes = mcrypt_create_iv(4, MCRYPT_DEV_URANDOM); - - if ($bytes === false || strlen($bytes) != 4) { - return false; - } - - $ary = unpack("Nint", $bytes); - $val = $ary['int'] & 0x7FFFFFFF; // 32-bit safe - $fp = (float)$val / 2147483647.0; // convert to [0,1] - - return round($fp * $diff) + $min; - } - - /** - * Return $quantity UNIQUE random value between $min and $max. - * Return false on failure. - * - * @param int $min = 0 - * @param int $max - * @param int $quantity = 1 - * - * @return array - */ - function getUniqueRandomValues($min = 0, $max, $quantity = 1) - { - if (!self::isInt($min) || !self::isInt($max) || !self::isInt($quantity) || $quantity < 1) { - return false; - } - - $rand = []; - - while (count($rand) < $quantity) { - $r = mt_rand($min, $max); - if (!in_array($r, $rand)) { - $rand[] = $r; - } - } - - return $rand; - } + /** + * Return today's day. + * + * @return string + */ + function getTodayDay() + { + $datetime = new \DateTime("now"); + + return $datetime->format("D"); + } + + /** + * Return today's day in format Y-m-d. Offset in days. + * Customize $format to receive the wanted date format. + * + * @param int $offset = 0 + * @param string $format = 'Y-m-d' + * + * @return string + */ + function getDate($offset = 0, $format = 'Y-m-d') + { + return date($format, strtotime($offset . ' day')); + } + + /** + * Return today's time in format H:i:s. Offset in minutes. + * Customize $format to receive the wanted time format. + * + * @param int $offset = 0 + * @param string $format = 'H:i:s' + * + * @return string + */ + function getTime($offset = 0, $format = 'H:i:s') + { + return date($format, strtotime($offset . ' minutes')); + } + + + // <<<--- PSEUDO-RANDOM NUMBERS METHODS --->>> + + + /** + * Return a random value between input $min and $max values by using the MCRYPT_DEV_URANDOM source. + * N.B. Use only on *nix servers! + * + * @param int $min = 0 + * @param int $max + * + * @return int + */ + static function getRandomValueUrandom($min = 0, $max = 0x7FFFFFFF) + { + if (!self::isInt($min) || !self::isInt($max) || $max < $min || ($max - $min) > 0x7FFFFFFF) { + return false; + } + + $diff = $max - $min; + + $bytes = mcrypt_create_iv(4, MCRYPT_DEV_URANDOM); + + if ($bytes === false || strlen($bytes) != 4) { + return false; + } + + $ary = unpack("Nint", $bytes); + $val = $ary['int'] & 0x7FFFFFFF; // 32-bit safe + $fp = (float)$val / 2147483647.0; // convert to [0,1] + + return round($fp * $diff) + $min; + } + + /** + * Return $quantity UNIQUE random value between $min and $max. + * Return false on failure. + * + * @param int $min = 0 + * @param int $max + * @param int $quantity = 1 + * + * @return array + */ + function getUniqueRandomValues($min = 0, $max, $quantity = 1) + { + if (!self::isInt($min) || !self::isInt($max) || !self::isInt($quantity) || $quantity < 1) { + return false; + } + + $rand = []; + + while (count($rand) < $quantity) { + $r = mt_rand($min, $max); + if (!in_array($r, $rand)) { + $rand[] = $r; + } + } + + return $rand; + } } diff --git a/src/MicheleAngioni/Support/Presenters/Presenter.php b/src/MicheleAngioni/Support/Presenters/Presenter.php index 898c356..509dd1e 100644 --- a/src/MicheleAngioni/Support/Presenters/Presenter.php +++ b/src/MicheleAngioni/Support/Presenters/Presenter.php @@ -7,59 +7,59 @@ class Presenter { - /** - * Return an instance of a Model wrapped in a presenter object - * - * @param Model $model - * @param PresentableInterface $presenter - * - * @return Model - */ - public function model(Model $model, PresentableInterface $presenter) - { - $object = clone $presenter; + /** + * Return an instance of a Model wrapped in a presenter object + * + * @param Model $model + * @param PresentableInterface $presenter + * + * @return Model + */ + public function model(Model $model, PresentableInterface $presenter) + { + $object = clone $presenter; - $object->set($model); + $object->set($model); - return $object; - } + return $object; + } - /** - * Return an instance of a Collection with each value wrapped in a presenter object - * - * @param Collection $collection - * @param PresentableInterface $presenter - * - * @return Collection - */ - public function collection(Collection $collection, PresentableInterface $presenter) - { - foreach ($collection as $key => $value) { - $collection->put($key, $this->model($value, $presenter)); - } + /** + * Return an instance of a Collection with each value wrapped in a presenter object + * + * @param Collection $collection + * @param PresentableInterface $presenter + * + * @return Collection + */ + public function collection(Collection $collection, PresentableInterface $presenter) + { + foreach ($collection as $key => $value) { + $collection->put($key, $this->model($value, $presenter)); + } - return $collection; - } + return $collection; + } - /** - * Return an instance of a Paginator with each value wrapped in a presenter object - * - * @param Paginator $paginator - * @param PresentableInterface $presenter - * - * @return Paginator - */ - public function paginator(Paginator $paginator, PresentableInterface $presenter) - { - $items = []; + /** + * Return an instance of a Paginator with each value wrapped in a presenter object + * + * @param Paginator $paginator + * @param PresentableInterface $presenter + * + * @return Paginator + */ + public function paginator(Paginator $paginator, PresentableInterface $presenter) + { + $items = []; - foreach ($paginator->getItems() as $item) { - $items[] = $this->model($item, $presenter); - } + foreach ($paginator->getItems() as $item) { + $items[] = $this->model($item, $presenter); + } - $paginator->setItems($items); + $paginator->setItems($items); - return $paginator; - } + return $paginator; + } } diff --git a/src/MicheleAngioni/Support/Repos/AbstractEloquentRepository.php b/src/MicheleAngioni/Support/Repos/AbstractEloquentRepository.php index 0a65005..11a957a 100644 --- a/src/MicheleAngioni/Support/Repos/AbstractEloquentRepository.php +++ b/src/MicheleAngioni/Support/Repos/AbstractEloquentRepository.php @@ -10,6 +10,7 @@ class AbstractEloquentRepository implements RepositoryCacheableQueriesInterface * Return all records. * * @param array $with + * * @return Collection */ public function all(array $with = []) @@ -54,6 +55,7 @@ public function find($id, array $with = []) * * @param $id * @param array $with + * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException * * @return mixed @@ -116,6 +118,7 @@ public function firstBy(array $where = [], array $with = []) * * @param array $where * @param array $with + * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException * * @return mixed @@ -149,7 +152,7 @@ public function getBy(array $where = [], array $with = []) /** * Return the first $limit records querying input parameters. * - * @param int $limit + * @param int $limit * @param array $where * @param array $with * @@ -321,6 +324,7 @@ public function hasFirst($relation, array $where = [], array $with = [], $hasAtL * @param array $where * @param array $with * @param int $hasAtLeast = 1 + * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException * * @return Collection @@ -391,6 +395,7 @@ public function getByPage($page = 1, $limit = 10, array $where = [], $with = [], * Create a collection of new records. * * @param array $collection + * * @return mixed */ public function insert(array $collection) @@ -406,6 +411,7 @@ public function insert(array $collection) * Create a new record. * * @param array $inputs + * * @return mixed */ public function create(array $inputs = []) @@ -419,6 +425,7 @@ public function create(array $inputs = []) * Update all records. * * @param array $inputs + * * @return mixed */ public function update(array $inputs) @@ -496,6 +503,7 @@ public function updateOrCreateBy(array $where, array $inputs = []) * Delete input record. * * @param int $id + * * @return mixed */ public function destroy($id) @@ -510,6 +518,7 @@ public function destroy($id) * Throws exception if no record is found. * * @param array $where + * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException * * @return mixed @@ -525,6 +534,7 @@ public function destroyFirstBy(array $where) * Retrieve and delete the all records matching input parameters. * * @param array $where + * * @return mixed */ public function destroyBy(array $where) diff --git a/src/MicheleAngioni/Support/SupportServiceProvider.php b/src/MicheleAngioni/Support/SupportServiceProvider.php index 713bf26..a5b6dc7 100644 --- a/src/MicheleAngioni/Support/SupportServiceProvider.php +++ b/src/MicheleAngioni/Support/SupportServiceProvider.php @@ -5,76 +5,76 @@ class SupportServiceProvider extends ServiceProvider { - /** - * Indicates if loading of the provider is deferred. - * - * @var bool - */ - protected $defer = false; + /** + * Indicates if loading of the provider is deferred. + * + * @var bool + */ + protected $defer = false; - /** - * Bootstrap the application events. - * - * @return void - */ - public function boot() - { - // Publish config files - $this->publishes([ - __DIR__ . '/../../config/config.php' => config_path('ma_support.php'), - ]); + /** + * Bootstrap the application events. + * + * @return void + */ + public function boot() + { + // Publish config files + $this->publishes([ + __DIR__ . '/../../config/config.php' => config_path('ma_support.php'), + ]); - $this->mergeConfigFrom( - __DIR__ . '/../../config/config.php', 'ma_support' - ); + $this->mergeConfigFrom( + __DIR__ . '/../../config/config.php', 'ma_support' + ); - $this->registerCustomValidators(); - } + $this->registerCustomValidators(); + } - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->registerHelpers(); - } + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->registerHelpers(); + } - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return []; + } - public function registerHelpers() - { - $this->app->bind('helpers', function () { - return new Helpers; - }); - } + public function registerHelpers() + { + $this->app->bind('helpers', function () { + return new Helpers; + }); + } - public function registerCustomValidators() - { - $validator = $this->app->make('Illuminate\Validation\Factory'); + public function registerCustomValidators() + { + $validator = $this->app->make('Illuminate\Validation\Factory'); - $validator->resolver(function ($translator, $data, $rules, $messages) { - $messages = [ - 'alpha_complete' => 'Only the following characters are allowed: alphabetic, numbers, spaces, slashes and several punctuation characters.', - 'alpha_space' => 'Only the following characters are allowed: alphabetic, numbers and spaces.', - 'alpha_underscore' => 'Only the following characters are allowed: alphabetic, numbers and underscores.', - 'alphanumeric_names' => 'Only the following characters are allowed: letters, numbers, menus, apostrophes, underscores and spaces.', - 'alphanumeric_dotted_names' => 'Only the following characters are allowed: letters, numbers, menus, apostrophes, underscores, dots and spaces.', - 'alpha_names' => 'Only the following characters are allowed: alphabetic, menus, apostrophes, underscores and spaces.', - ]; + $validator->resolver(function ($translator, $data, $rules, $messages) { + $messages = [ + 'alpha_complete' => 'Only the following characters are allowed: alphabetic, numbers, spaces, slashes and several punctuation characters.', + 'alpha_space' => 'Only the following characters are allowed: alphabetic, numbers and spaces.', + 'alpha_underscore' => 'Only the following characters are allowed: alphabetic, numbers and underscores.', + 'alphanumeric_names' => 'Only the following characters are allowed: letters, numbers, menus, apostrophes, underscores and spaces.', + 'alphanumeric_dotted_names' => 'Only the following characters are allowed: letters, numbers, menus, apostrophes, underscores, dots and spaces.', + 'alpha_names' => 'Only the following characters are allowed: alphabetic, menus, apostrophes, underscores and spaces.', + ]; - return new CustomValidators($translator, $data, $rules, $messages); - }); - } + return new CustomValidators($translator, $data, $rules, $messages); + }); + } } diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php index 55ad4e6..afb2a98 100644 --- a/tests/HelpersTest.php +++ b/tests/HelpersTest.php @@ -2,9 +2,10 @@ use MicheleAngioni\Support\Helpers as H; -class HelpersTest extends PHPUnit_Framework_TestCase { +class HelpersTest extends PHPUnit_Framework_TestCase +{ - public function testIsInt() + public function testIsInt() { $object = new stdClass(); diff --git a/tests/SemaphoreTest.php b/tests/SemaphoreTest.php index b0f652a..13d23a4 100644 --- a/tests/SemaphoreTest.php +++ b/tests/SemaphoreTest.php @@ -1,15 +1,17 @@ mock('MicheleAngioni\Support\Cache\CacheInterface'); $keyManagerInterface = $this->mock('MicheleAngioni\Support\Cache\KeyManagerInterface'); - $semaphoreManager = new MicheleAngioni\Support\Semaphores\SemaphoresManager($cacheInterface, $keyManagerInterface); + $semaphoreManager = new MicheleAngioni\Support\Semaphores\SemaphoresManager($cacheInterface, + $keyManagerInterface); $semaphoreManager->setLockingTime($lockingTime); @@ -24,7 +26,8 @@ public function testGetSemaphoreKey() $keyManagerInterface->shouldReceive('getKey') ->andReturn(true); - $semaphoreManager = new MicheleAngioni\Support\Semaphores\SemaphoresManager($cacheInterface, $keyManagerInterface); + $semaphoreManager = new MicheleAngioni\Support\Semaphores\SemaphoresManager($cacheInterface, + $keyManagerInterface); $semaphoreManager->getSemaphoreKey('id', 'section'); } @@ -34,13 +37,14 @@ public function testLockSemaphore() $cacheInterface = $this->mock('MicheleAngioni\Support\Cache\CacheInterface'); $keyManagerInterface = $this->mock('MicheleAngioni\Support\Cache\KeyManagerInterface'); - $semaphoreManager = Mockery::mock('MicheleAngioni\Support\Semaphores\SemaphoresManager[getSemaphoreKey]', array($cacheInterface, $keyManagerInterface)); + $semaphoreManager = Mockery::mock('MicheleAngioni\Support\Semaphores\SemaphoresManager[getSemaphoreKey]', + [$cacheInterface, $keyManagerInterface]); $semaphoreManager->shouldReceive('getSemaphoreKey') - ->andReturn('string'); + ->andReturn('string'); $cacheInterface->shouldReceive('put') - ->andReturn(true); + ->andReturn(true); $semaphoreManager->lockSemaphore('id', 'section'); } @@ -50,7 +54,8 @@ public function testUnlockSemaphore() $cacheInterface = $this->mock('MicheleAngioni\Support\Cache\CacheInterface'); $keyManagerInterface = $this->mock('MicheleAngioni\Support\Cache\KeyManagerInterface'); - $semaphoreManager = Mockery::mock('MicheleAngioni\Support\Semaphores\SemaphoresManager[getSemaphoreKey]', array($cacheInterface, $keyManagerInterface)); + $semaphoreManager = Mockery::mock('MicheleAngioni\Support\Semaphores\SemaphoresManager[getSemaphoreKey]', + [$cacheInterface, $keyManagerInterface]); $semaphoreManager->shouldReceive('getSemaphoreKey') ->andReturn('string');