As good as its getting today.
This commit is contained in:
parent
fd9df587de
commit
2780e16794
10 changed files with 50 additions and 78 deletions
|
@ -38,6 +38,8 @@
|
|||
"friendsofphp/php-cs-fixer": "^3.0",
|
||||
"kint-php/kint": "^4.0",
|
||||
"kint-php/kint-twig": "^4.0",
|
||||
"league/flysystem": "^3.27",
|
||||
"league/flysystem-local": "^3.25",
|
||||
"matthewbaggett/inflection": "^2.1",
|
||||
"matthewbaggett/uuid": "^2.3",
|
||||
"mattketmo/camel": "^1.1",
|
||||
|
@ -88,7 +90,8 @@
|
|||
"wyrihaximus/html-compress": "^4.1"
|
||||
},
|
||||
"suggest": {
|
||||
"benzine/orm": "Model/Service/Crud generation made easy"
|
||||
"benzine/orm": "Model/Service/Crud generation made easy",
|
||||
"league/flysystem-aws-s3-v3": "underlying support for s3 bucket stores using flysystem"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
12
src/App.php
12
src/App.php
|
@ -40,6 +40,7 @@ use Middlewares\ContentLength;
|
|||
use Middlewares\TrailingSlash;
|
||||
use Monolog\Formatter\LineFormatter;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Level;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Processor\PsrLogMessageProcessor;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
@ -344,7 +345,7 @@ class App
|
|||
)));
|
||||
|
||||
// Configure a pretty CLI Handler
|
||||
$cliHandler = new StreamHandler('php://stdout', Logger::DEBUG);
|
||||
$cliHandler = new StreamHandler('php://stdout', Level::Debug);
|
||||
$cliFormatter = new ColoredLineFormatter(
|
||||
new TrafficLight(),
|
||||
// the default output format is "[%datetime%] %channel%.%level_name%: %message% %context% %extra%"
|
||||
|
@ -357,9 +358,10 @@ class App
|
|||
return $monolog;
|
||||
});
|
||||
|
||||
$container->set(Redis::class, function (Logger $logger, EnvironmentService $environmentService) {
|
||||
$container->set(Redis::class, function (ConfigurationService $configurationService, Logger $logger, EnvironmentService $environmentService) {
|
||||
return new Redis(
|
||||
$logger,
|
||||
$configurationService,
|
||||
$environmentService->get('REDIS_HOST', 'redis'),
|
||||
$environmentService->get('REDIS_PORT', 6379),
|
||||
$environmentService->get('REDIS_PASSWORD', null),
|
||||
|
@ -385,7 +387,7 @@ class App
|
|||
->addCollector(new TimeDataCollector())
|
||||
->addCollector(new MemoryCollector())
|
||||
->addCollector(new ExceptionsCollector())
|
||||
->addCollector(new MonologCollector($logger, Logger::DEBUG))
|
||||
->addCollector(new MonologCollector($logger, Level::Debug))
|
||||
;
|
||||
});
|
||||
|
||||
|
@ -469,9 +471,9 @@ class App
|
|||
return $this;
|
||||
}
|
||||
|
||||
public static function Log($message, int $level = Logger::DEBUG)
|
||||
public static function Log($message, Level $level = Level::Debug): void
|
||||
{
|
||||
return self::Instance()
|
||||
self::Instance()
|
||||
->getLogger()
|
||||
->log($level, ($message instanceof \Exception) ? $message->__toString() : $message)
|
||||
;
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Benzine\Controllers;
|
||||
|
||||
use Benzine\ORM\Abstracts\AbstractService;
|
||||
use Benzine\ORM\Interfaces\ModelInterface;
|
||||
use Laminas\Db\Adapter\Exception\InvalidQueryException;
|
||||
use Slim\Psr7\Request;
|
||||
|
@ -11,6 +12,8 @@ use Slim\Psr7\Response;
|
|||
|
||||
abstract class AbstractCrudController extends AbstractController
|
||||
{
|
||||
abstract protected function getService(): AbstractService;
|
||||
|
||||
public function listRequest(Request $request, Response $response): Response
|
||||
{
|
||||
$objects = [];
|
||||
|
@ -34,9 +37,9 @@ abstract class AbstractCrudController extends AbstractController
|
|||
|
||||
return $this->jsonResponse(
|
||||
[
|
||||
'Status' => 'Okay',
|
||||
'Action' => 'LIST',
|
||||
$this->service->getTermPlural() => $objects,
|
||||
'Status' => 'Okay',
|
||||
'Action' => 'LIST',
|
||||
$this->getService()->getTermPlural() => $objects,
|
||||
],
|
||||
$request,
|
||||
$response
|
||||
|
@ -51,7 +54,7 @@ abstract class AbstractCrudController extends AbstractController
|
|||
[
|
||||
'Status' => 'Okay',
|
||||
'Action' => 'GET',
|
||||
$this->service->getTermSingular() => $object->__toArray(),
|
||||
$this->getService()->getTermSingular() => $object->__toArray(),
|
||||
],
|
||||
$request,
|
||||
$response
|
||||
|
@ -63,7 +66,7 @@ abstract class AbstractCrudController extends AbstractController
|
|||
'Status' => 'Fail',
|
||||
'Reason' => sprintf(
|
||||
'No such %s found with id %s',
|
||||
strtolower($this->service->getTermSingular()),
|
||||
strtolower($this->getService()->getTermSingular()),
|
||||
$args['id']
|
||||
),
|
||||
],
|
||||
|
@ -83,7 +86,7 @@ abstract class AbstractCrudController extends AbstractController
|
|||
[
|
||||
'Status' => 'Okay',
|
||||
'Action' => 'CREATE',
|
||||
$this->service->getTermSingular() => $object->__toArray(),
|
||||
$this->getService()->getTermSingular() => $object->__toArray(),
|
||||
],
|
||||
$request,
|
||||
$response
|
||||
|
@ -105,7 +108,7 @@ abstract class AbstractCrudController extends AbstractController
|
|||
[
|
||||
'Status' => 'Okay',
|
||||
'Action' => 'DELETE',
|
||||
$this->service->getTermSingular() => $array,
|
||||
$this->getService()->getTermSingular() => $array,
|
||||
],
|
||||
$request,
|
||||
$response
|
||||
|
|
|
@ -58,9 +58,8 @@ class JsonValidationMiddleware implements MiddlewareInterface
|
|||
// Whelp, we've failed validation, build a failure message.
|
||||
$response = new Response();
|
||||
$content = json_encode([
|
||||
'Status' => 'FAIL',
|
||||
'Reason' => "Invalid JSON, doesn't match schema!",
|
||||
'Error' => $exception->getMessage(),
|
||||
'Status' => 'FAIL',
|
||||
'Reason' => "Invalid JSON, doesn't match schema! {$exception->getMessage()}",
|
||||
], JSON_PRETTY_PRINT);
|
||||
|
||||
$response->getBody()->write($content);
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Benzine\Redis;
|
||||
|
||||
use Benzine\Services\ConfigurationService;
|
||||
use Monolog\Logger;
|
||||
|
||||
class Redis
|
||||
|
@ -227,15 +228,18 @@ class Redis
|
|||
private ?string $password;
|
||||
private float $timeout;
|
||||
private \Redis $redis;
|
||||
private Logger $logger;
|
||||
|
||||
/** @var Lua\AbstractLuaExtension[] */
|
||||
private array $scripts;
|
||||
|
||||
public function __construct(Logger $logger, string $host, int $port = 6379, ?string $password = null, float $timeout = 0.0)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
|
||||
public function __construct(
|
||||
private Logger $logger,
|
||||
private ConfigurationService $configurationService,
|
||||
string $host,
|
||||
int $port = 6379,
|
||||
?string $password = null,
|
||||
float $timeout = 0.0
|
||||
) {
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
$this->password = $password;
|
||||
|
@ -299,7 +303,7 @@ class Redis
|
|||
|
||||
public function emit(array $message)
|
||||
{
|
||||
return $this->redis->publish(strtolower(APP_NAME), json_encode($message));
|
||||
return $this->redis->publish(strtolower($this->configurationService->get(ConfigurationService::KEY_APP_NAME)), json_encode($message));
|
||||
}
|
||||
|
||||
public function listen($callback): void
|
||||
|
@ -307,8 +311,9 @@ class Redis
|
|||
ini_set('default_socket_timeout', -1);
|
||||
|
||||
try {
|
||||
$this->redis->psubscribe([strtolower(APP_NAME)], $callback);
|
||||
} catch (\RedisException $exception) {
|
||||
$this->redis->psubscribe([strtolower($this->configurationService->get(ConfigurationService::KEY_APP_NAME))], $callback);
|
||||
} catch (\RedisException) {
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,10 +12,10 @@ abstract class AbstractQueueWorker extends AbstractWorker
|
|||
{
|
||||
protected QueueService $queueService;
|
||||
|
||||
/** @var string Name of the input redis queue */
|
||||
/** @var ?string Name of the input redis queue */
|
||||
protected ?string $inputQueue;
|
||||
|
||||
/** @var string[] Name of the output redis queues */
|
||||
/** @var ?string[] Name of the output redis queues */
|
||||
protected ?array $outputQueues;
|
||||
|
||||
protected ?array $resultItems;
|
||||
|
|
|
@ -8,7 +8,7 @@ use Benzine\Redis\Redis;
|
|||
use Benzine\Services\EnvironmentService;
|
||||
use Monolog\Logger;
|
||||
|
||||
abstract class WaitForEmitWorker extends AbstractWorker
|
||||
abstract class AbstractWaitForEmitWorker extends AbstractWorker
|
||||
{
|
||||
public $callback;
|
||||
protected array $messageTypes = [];
|
|
@ -5,19 +5,16 @@ declare(strict_types=1);
|
|||
namespace Benzine\Tests;
|
||||
|
||||
use Faker\Factory as FakerFactory;
|
||||
use Faker\Generator;
|
||||
use Faker\Generator as Faker;
|
||||
use Faker\Provider;
|
||||
|
||||
abstract class AbstractBaseTestCase extends AbstractTestCase
|
||||
{
|
||||
// Set this to true if you want to see whats going on inside some unit tests..
|
||||
public const DEBUG_MODE = false;
|
||||
private static Faker $faker;
|
||||
|
||||
private static Generator $faker;
|
||||
|
||||
public function __construct($name = null, array $data = [], $dataName = '')
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name, $data, $dataName);
|
||||
parent::__construct($name);
|
||||
|
||||
// Force Kint into CLI mode.
|
||||
\Kint::$mode_default = \Kint::MODE_CLI;
|
||||
|
@ -38,10 +35,7 @@ abstract class AbstractBaseTestCase extends AbstractTestCase
|
|||
self::$faker->addProvider(new Provider\en_US\Company(self::$faker));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Generator
|
||||
*/
|
||||
public static function getFaker()
|
||||
public static function getFaker(): Faker
|
||||
{
|
||||
return self::$faker;
|
||||
}
|
||||
|
@ -55,7 +49,7 @@ abstract class AbstractBaseTestCase extends AbstractTestCase
|
|||
*
|
||||
* @return mixed method return
|
||||
*/
|
||||
public function invokeMethod(&$object, $methodName, array $parameters = [])
|
||||
public function invokeMethod(&$object, $methodName, array $parameters = []) : mixed
|
||||
{
|
||||
$reflection = new \ReflectionClass($object::class);
|
||||
$method = $reflection->getMethod($methodName);
|
||||
|
@ -64,13 +58,14 @@ abstract class AbstractBaseTestCase extends AbstractTestCase
|
|||
return $method->invokeArgs($object, $parameters);
|
||||
}
|
||||
|
||||
public function setProtectedProperty(&$object, $property, $value)
|
||||
public function setProtectedProperty(&$object, $property, $value) : self
|
||||
{
|
||||
$reflection = new \ReflectionClass($object::class);
|
||||
$prop = $reflection->getProperty($property);
|
||||
$prop->setAccessible(true);
|
||||
$prop->setValue($object, $value);
|
||||
|
||||
return $prop->setValue($object, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProtectedProperty(&$object, $property)
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace Benzine\Tests;
|
|||
|
||||
use Benzine\App;
|
||||
use Benzine\Services\EnvironmentService;
|
||||
use Facebook\WebDriver\Exception\NoSuchElementException;
|
||||
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
||||
use Facebook\WebDriver\Remote\RemoteWebElement;
|
||||
use Facebook\WebDriver\Remote\WebDriverCapabilityType;
|
||||
|
@ -60,7 +61,7 @@ abstract class AbstractSeleniumTestCase extends AbstractBaseTestCase
|
|||
{
|
||||
try {
|
||||
return self::$webDriver->findElement(WebDriverBy::cssSelector($sizzleSelector));
|
||||
} catch (NoSuchElementException $noSuchElementException) {
|
||||
} catch (NoSuchElementException) {
|
||||
self::$logger->debug("Couldn't find a match for sizzle selector '{$sizzleSelector}'");
|
||||
|
||||
return null;
|
||||
|
|
|
@ -10,40 +10,4 @@ abstract class AbstractTestCase extends TestCase
|
|||
{
|
||||
use Traits\OverrideProtectionTrait;
|
||||
use Traits\ArrayEquitabilityTrait;
|
||||
|
||||
private $singleTestTime;
|
||||
|
||||
private $waypoint_count;
|
||||
private $waypoint_last_time;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->singleTestTime = microtime(true);
|
||||
$this->waypoint_count = 0;
|
||||
$this->waypoint_last_time = $this->singleTestTime;
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
if (defined('DEBUG') && DEBUG) {
|
||||
$time = microtime(true) - $this->singleTestTime;
|
||||
echo '' . get_called_class() . ':' . $this->getName() . ': Took ' . number_format($time, 3) . " seconds\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function waypoint($message = ''): void
|
||||
{
|
||||
if (defined('DEBUG') && DEBUG) {
|
||||
$time_since_last_waypoint = number_format((microtime(true) - $this->waypoint_last_time) * 1000, 2, '.', '');
|
||||
$time_since_begin = number_format((microtime(true) - $this->singleTestTime) * 1000, 2, '.', '');
|
||||
++$this->waypoint_count;
|
||||
if (1 == $this->waypoint_count) {
|
||||
echo "\n";
|
||||
}
|
||||
echo " > Waypoint {$this->waypoint_count} - {$time_since_last_waypoint}ms / {$time_since_begin}ms {$message}\n";
|
||||
$this->waypoint_last_time = microtime(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue