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

Upgrade Optimus package #37

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
"docs": "https://github.com/cybercog/laravel-optimus/wiki"
},
"require": {
"php": "^7.1.3|^8.0",
"php": "^8.0",
"graham-campbell/manager": "^4.0",
"illuminate/contracts": "^5.5|^6.0|^7.0|^8.0|^9.0",
"illuminate/support": "^5.5|^6.0|^7.0|^8.0|^9.0",
"jenssegers/optimus": "^0.2.2"
"illuminate/contracts": "^9.0",
"illuminate/support": "^9.0",
"jenssegers/optimus": "^1.0"
},
"require-dev": {
"graham-campbell/testbench": "^5.0",
Expand Down
5 changes: 5 additions & 0 deletions config/optimus.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
| configuration has been included, but you may add as many connections as
| you would like.
|
| Laravel Optimus depends on jenssegers/optimus, we need three values:
| - A large `prime` number lower than 2147483647
| - The `inverse` prime so that (PRIME * INVERSE) & MAXID == 1
| - A large `random` integer lower than 2147483647
|
*/

'connections' => [
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">tests/</directory>
<exclude>tests/database/factories/</exclude>
</testsuite>
</testsuites>
<php>
Expand Down
32 changes: 26 additions & 6 deletions src/OptimusFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Cog\Laravel\Optimus;

use Illuminate\Support\Arr;
use InvalidArgumentException;
use Jenssegers\Optimus\Optimus;

class OptimusFactory
Expand All @@ -35,16 +35,36 @@ public function make(array $config): Optimus
* Get the configuration data.
*
* @param array $config
* @return array
* @return array<string, int>
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
protected function getConfig(array $config): array
{
$prime = $config['prime'] ?? null;
$inverse = $config['inverse'] ?? null;
$random = $config['random'] ?? null;

if (is_int($prime) === false) {
throw new InvalidArgumentException(
"Optimus `prime` value must be integer but `$prime` provided",
);
}
if (is_int($prime) === false) {
throw new InvalidArgumentException(
"Optimus `inverse` value must be integer `$inverse` provided",
);
}
if (is_int($random) === false) {
throw new InvalidArgumentException(
"Optimus `random` value must be integer `$random` provided",
);
}

return [
'prime' => Arr::get($config, 'prime', 0),
'inverse' => Arr::get($config, 'inverse', 0),
'random' => Arr::get($config, 'random', 0),
'prime' => $prime,
'inverse' => $inverse,
'random' => $random,
];
}

Expand Down
6 changes: 3 additions & 3 deletions tests/OptimusFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public function testMakeStandard(): void
$factory = $this->getOptimusFactory();

$return = $factory->make([
'prime' => 'your-prime-integer',
'inverse' => 'your-inverse-integer',
'random' => 'your-random-integer',
'prime' => 0,
'inverse' => 0,
'random' => 0,
]);

$this->assertInstanceOf(Optimus::class, $return);
Expand Down
5 changes: 5 additions & 0 deletions tests/Providers/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public function testOptimusManagerIsInjectable(): void

public function testBindings(): void
{
$appConfig = $this->app->get('config');
$appConfig->set('optimus.connections.main.prime', 0);
$appConfig->set('optimus.connections.main.inverse', 0);
$appConfig->set('optimus.connections.main.random', 0);

$this->assertIsInjectable(Optimus::class);

$original = $this->app['optimus.connection'];
Expand Down