Skip to content

Commit

Permalink
fix: unity tests
Browse files Browse the repository at this point in the history
  • Loading branch information
papac committed Jan 26, 2025
1 parent 0b40383 commit 1a70018
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 65 deletions.
5 changes: 3 additions & 2 deletions src/Mail/Envelop.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

namespace Bow\Mail;

use Bow\Mail\Exception\MailException;
use Bow\View\View;
use Bow\Support\Str;
use InvalidArgumentException;
use Bow\Mail\Exception\MailException;

class Envelop
{
Expand Down Expand Up @@ -486,7 +487,7 @@ public function fromIsDefined(): bool
*/
public function view(string $view, array $data = []): Envelop
{
$this->message(view($view, $data)->getContent());
$this->message(View::parse($view, $data)->getContent());

return $this;
}
Expand Down
22 changes: 9 additions & 13 deletions tests/Messaging/MessagingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Bow\Tests\Messaging;

use Bow\Database\Barry\Model;
use Bow\View\View;
use Bow\Mail\Envelop;
use Bow\Messaging\MessagingQueueProducer;
use Bow\Queue\Connection as QueueConnection;
use Bow\Database\Barry\Model;
use PHPUnit\Framework\TestCase;
use Bow\Tests\Config\TestingConfiguration;
use Bow\Tests\Messaging\Stubs\TestMessage;
use Bow\Tests\Messaging\Stubs\TestNotifiableModel;
use Bow\Queue\Connection as QueueConnection;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Bow\Tests\Messaging\Stubs\TestNotifiableModel;

class MessagingTest extends TestCase
{
Expand All @@ -22,14 +23,9 @@ public static function setUpBeforeClass(): void
parent::setUpBeforeClass();

// Initialize queue connection
static::$queueConnection = new QueueConnection([
'default' => 'sync',
'connections' => [
'sync' => [
'driver' => 'sync'
]
]
]);
$config = TestingConfiguration::getConfig();

View::configure($config["view"]);
}

public function test_can_send_message_synchronously(): void
Expand Down
17 changes: 10 additions & 7 deletions tests/Queue/EventQueueTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?php

use Bow\Cache\CacheConfiguration;
use Bow\Configuration\EnvConfiguration;
use Bow\Configuration\LoggerConfiguration;
namespace Bow\Tests\Queue;

use Bow\Queue\Connection;
use Bow\Event\EventProducer;
use Bow\Mail\MailConfiguration;
use Bow\Queue\Connection;
use Bow\View\ViewConfiguration;
use PHPUnit\Framework\TestCase;
use Bow\Cache\CacheConfiguration;
use Bow\Queue\QueueConfiguration;
use Bow\Configuration\EnvConfiguration;
use Bow\Tests\Events\Stubs\UserEventStub;
use Bow\Configuration\LoggerConfiguration;
use Bow\Tests\Config\TestingConfiguration;
use Bow\Tests\Events\Stubs\UserEventListenerStub;
use Bow\Tests\Events\Stubs\UserEventStub;
use Bow\View\ViewConfiguration;

class EventQueueTest extends \PHPUnit\Framework\TestCase
class EventQueueTest extends TestCase
{
private static $connection;

Expand Down
15 changes: 9 additions & 6 deletions tests/Queue/MailQueueTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<?php

use Bow\Cache\CacheConfiguration;
use Bow\Configuration\EnvConfiguration;
use Bow\Configuration\LoggerConfiguration;
namespace Bow\Tests\Queue;

use Bow\Mail\Envelop;
use Bow\Mail\MailConfiguration;
use Bow\Mail\MailQueueProducer;
use Bow\Queue\Connection as QueueConnection;
use Bow\View\ViewConfiguration;
use PHPUnit\Framework\TestCase;
use Bow\Cache\CacheConfiguration;
use Bow\Queue\QueueConfiguration;
use Bow\Configuration\EnvConfiguration;
use Bow\Configuration\LoggerConfiguration;
use Bow\Tests\Config\TestingConfiguration;
use Bow\View\ViewConfiguration;
use Bow\Queue\Connection as QueueConnection;

class MailQueueTest extends PHPUnit\Framework\TestCase
class MailQueueTest extends TestCase
{
private static $connection;

Expand Down
63 changes: 36 additions & 27 deletions tests/Queue/MessagingQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,49 @@
namespace Bow\Tests\Queue;

use Bow\Database\Barry\Model;
use Bow\Mail\MailConfiguration;
use Bow\View\ViewConfiguration;
use PHPUnit\Framework\TestCase;
use Bow\Cache\CacheConfiguration;
use Bow\Queue\QueueConfiguration;
use Bow\Configuration\EnvConfiguration;
use Bow\Messaging\MessagingQueueProducer;
use Bow\Queue\Connection as QueueConnection;
use Bow\Configuration\LoggerConfiguration;
use Bow\Tests\Config\TestingConfiguration;
use Bow\Tests\Messaging\Stubs\TestMessage;
use Bow\Tests\Messaging\Stubs\TestNotifiableModel;
use Bow\Queue\Connection as QueueConnection;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Bow\Tests\Messaging\Stubs\TestNotifiableModel;

class MessagingTest extends TestCase
class MessagingQueueTest extends TestCase
{
private static QueueConnection $queueConnection;
private static QueueConnection $connection;
private MockObject|Model $context;
private MockObject|TestMessage $message;

public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();

// Initialize queue connection
static::$queueConnection = new QueueConnection([
'default' => 'sync',
'connections' => [
'sync' => [
'driver' => 'sync'
]
]
TestingConfiguration::withConfigurations([
CacheConfiguration::class,
QueueConfiguration::class,
EnvConfiguration::class,
LoggerConfiguration::class,
MailConfiguration::class,
ViewConfiguration::class,
]);

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

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

protected function setUp(): void
{
parent::setUp();

$this->context = $this->createMock(TestNotifiableModel::class);
$this->message = $this->createMock(TestMessage::class);
}

public function test_can_send_message_synchronously(): void
Expand All @@ -48,7 +65,7 @@ public function test_can_send_message_to_queue(): void
$this->assertInstanceOf(MessagingQueueProducer::class, $producer);

// Push to queue and verify
static::$queueConnection->getAdapter()->push($producer);
static::$connection->setConnection("beanstalkd")->getAdapter()->push($producer);

$this->context->setMessageQueue($this->message);
}
Expand All @@ -62,7 +79,7 @@ public function test_can_send_message_to_specific_queue(): void
$this->assertInstanceOf(MessagingQueueProducer::class, $producer);

// Push to specific queue and verify
$adapter = static::$queueConnection->getAdapter();
$adapter = static::$connection->setConnection("beanstalkd")->getAdapter();
$adapter->setQueue($queue);
$adapter->push($producer);

Expand All @@ -78,7 +95,7 @@ public function test_can_send_message_with_delay(): void
$this->assertInstanceOf(MessagingQueueProducer::class, $producer);

// Push to queue and verify
$adapter = static::$queueConnection->getAdapter();
$adapter = static::$connection->setConnection("beanstalkd")->getAdapter();
$adapter->setSleep($delay);
$adapter->push($producer);

Expand All @@ -95,19 +112,11 @@ public function test_can_send_message_with_delay_on_specific_queue(): void
$this->assertInstanceOf(MessagingQueueProducer::class, $producer);

// Push to specific queue with delay and verify
$adapter = static::$queueConnection->getAdapter();
$adapter = static::$connection->setConnection("beanstalkd")->getAdapter();
$adapter->setQueue($queue);
$adapter->setSleep($delay);
$adapter->push($producer);

$this->context->sendMessageLaterOn($delay, $queue, $this->message);
}

protected function setUp(): void
{
parent::setUp();

$this->context = $this->createMock(TestNotifiableModel::class);
$this->message = $this->createMock(TestMessage::class);
}
}
21 changes: 11 additions & 10 deletions tests/Queue/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

namespace Bow\Tests\Queue;

use Bow\Cache\Adapters\RedisAdapter;
use Bow\Database\Database;
use PHPUnit\Framework\TestCase;
use Bow\Cache\CacheConfiguration;
use Bow\Queue\Adapters\SQSAdapter;
use Bow\Queue\Adapters\SyncAdapter;
use Bow\Cache\Adapters\RedisAdapter;
use Bow\Configuration\EnvConfiguration;
use Bow\Configuration\LoggerConfiguration;
use Bow\Database\Database;
use Bow\Database\DatabaseConfiguration;
use Bow\Queue\Adapters\BeanstalkdAdapter;
use Bow\Queue\Adapters\DatabaseAdapter;
use Bow\Queue\Adapters\SQSAdapter;
use Bow\Queue\Adapters\SyncAdapter;
use Bow\Queue\Connection as QueueConnection;
use Bow\Tests\Queue\Stubs\PetModelStub;
use Bow\Queue\Adapters\BeanstalkdAdapter;
use Bow\Configuration\LoggerConfiguration;
use Bow\Tests\Config\TestingConfiguration;
use Bow\Tests\Queue\Stubs\BasicProducerStubs;
use Bow\Queue\Connection as QueueConnection;
use Bow\Tests\Queue\Stubs\ModelProducerStub;
use Bow\Tests\Queue\Stubs\PetModelStub;
use Bow\Tests\Queue\Stubs\BasicProducerStubs;

class QueueTest extends \PHPUnit\Framework\TestCase
class QueueTest extends TestCase
{
private static $connection;

Expand Down

0 comments on commit 1a70018

Please sign in to comment.