Skip to content

Commit

Permalink
Merge branch '5.x' into feat-integrate-queue-adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
papac authored Sep 22, 2023
2 parents 1c909ff + c4220ad commit fb55cd0
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/Auth/Guards/JwtGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ public function check(): bool
$policier = $this->getPolicier();

if (is_null($this->token)) {
$this->token = $policier->getParsedToken();
try {
$this->token = $policier->getParsedToken();
} catch (\Exception $e) {
return false;
}
}

if (is_null($this->token)) {
Expand Down
5 changes: 2 additions & 3 deletions src/Queue/Adapters/BeanstalkdAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ public function size(?string $queue = null): int
*/
public function push(ProducerService $producer): void
{
// TODO: should be removed
// $this->flush();
$queues = (array) cache("beanstalkd:queues");

if (!in_array($producer->getQueue(), $queues)) {
$queues[] = $producer->getQueue();
cache("beanstalkd:queues", $queues);
}
$queues = (array) cache("beanstalkd:queues");
dump($queues);

$this->pheanstalk
->useTube($producer->getQueue())
Expand Down Expand Up @@ -168,7 +168,6 @@ public function run(string $queue = null): void
try {
$payload = $job->getData();
$producer = $this->unserializeProducer($payload);
dump($producer);
call_user_func([$producer, "process"]);
$this->sleep(2);
$this->pheanstalk->touch($job);
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/KernelTesting.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class KernelTesting extends ConfigurationLoader
* @param array $configurations
* @return void
*/
public static function withConfiguations(array $configurations): void
public static function withConfigurations(array $configurations): void
{
static::$configurations = $configurations;
}
Expand Down
33 changes: 33 additions & 0 deletions tests/Config/TestingConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,39 @@ public function __construct()
is_dir(TESTING_RESOURCE_BASE_DIRECTORY) || mkdir(TESTING_RESOURCE_BASE_DIRECTORY, 0777);
}

/**
* Configure the testing
*
* @param array $configurations
* @return void
*/
public static function withConfigurations(array $configurations)
{
KernelTesting::withConfigurations($configurations);
}

/**
* Configure the testing
*
* @param array $middlewares
* @return void
*/
public static function withMiddlewares(array $middlewares)
{
KernelTesting::withMiddlewares($middlewares);
}

/**
* Set the loading events
*
* @param array $events
* @return void
*/
public static function withEvents(array $events): void
{
KernelTesting::withEvents($events);
}

/**
* Get the configuration for testing
*
Expand Down
14 changes: 12 additions & 2 deletions tests/Queue/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

use Bow\Cache\Adapter\RedisAdapter;
use Bow\Cache\Cache;
use Bow\Cache\CacheConfiguration;
use Bow\Configuration\LoggerConfiguration;
use Bow\Database\Database;
use Bow\Database\DatabaseConfiguration;
use Bow\Queue\Adapters\BeanstalkdAdapter;
use Bow\Queue\Adapters\SQSAdapter;
use Bow\Tests\Config\TestingConfiguration;
use Bow\Tests\Queue\Stubs\PetModelStub;
use Bow\Queue\Connection as QueueConnection;
use Bow\Testing\KernelTesting;
use Bow\Tests\Queue\Stubs\ModelProducerStub;
use Bow\Tests\Queue\Stubs\BasicProducerStubs;

Expand All @@ -19,11 +23,17 @@ class QueueTest extends \PHPUnit\Framework\TestCase

public static function setUpBeforeClass(): void
{
TestingConfiguration::withConfigurations([
LoggerConfiguration::class,
DatabaseConfiguration::class,
CacheConfiguration::class,
]);

$config = TestingConfiguration::getConfig();
$config->boot();

static::$connection = new QueueConnection($config["queue"]);

Database::configure($config["database"]);
Cache::configure($config["cache"]);
Database::connection('mysql');
Database::statement('drop table if exists pets');
Database::statement('create table pets (id int primary key auto_increment, name varchar(255))');
Expand Down
6 changes: 3 additions & 3 deletions tests/Support/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function test_get_method()
{
$http = new HttpClient();

$response = $http->get("https://google.com");
$response = $http->get("https://www.oogle.com");

$this->assertEquals($response->statusCode(), 200);
}
Expand All @@ -21,14 +21,14 @@ public function test_get_method_with_custom_headers()
$http = new HttpClient();

$http->addHeaders(["X-Api-Key" => "Fake-Key"]);
$response = $http->get("https://google.com");
$response = $http->get("https://www.google.com");

$this->assertEquals($response->statusCode(), 200);
}

public function test_should_be_fail_with_get_method()
{
$http = new HttpClient("https://google.com");
$http = new HttpClient("https://www.google.com");

$http->addHeaders(["X-Api-Key" => "Fake-Key"]);
$response = $http->get("/the-fake-url");
Expand Down

0 comments on commit fb55cd0

Please sign in to comment.