Skip to content

Commit 06f3389

Browse files
authored
Merge pull request #338 from bowphp/refactor/code-base
Refactoring queue and add more testing
2 parents d1cdcaa + 4fb561e commit 06f3389

61 files changed

Lines changed: 1637 additions & 675 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ jobs:
6767
run: if [ ! -d /tmp/bowphp_testing ]; then mkdir -p /tmp/bowphp_testing; fi;
6868

6969
- name: Run test suite
70-
run: sudo composer run-script test
70+
run: sudo composer run-script test || sudo composer run-script testdox

CHANGELOG.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424

2525
## 5.1.2 - 2023-09-17
2626

27-
Fix `db_seed` helper
27+
Fix `app_db_seed` helper
2828

2929
Ref
3030

@@ -60,16 +60,15 @@ Reference #248
6060

6161
## 5.0.8 - 2023-05-24
6262

63-
Release 5.0.8
64-
63+
Release **5.0.8**
6564
Fixes test case errors
6665

6766
Reference #243
6867
From #242
6968

7069
## 5.0.7 - 2023-05-24
7170

72-
Release 5.0.7
71+
Release **5.0.7**
7372

7473
- Fixes the database relationship
7574
- Fixes the HTTP client
@@ -81,7 +80,7 @@ Fixes #240
8180

8281
## 5.0.6 - 2023-05-22
8382

84-
Release 5.0.6
83+
Release **5.0.6**
8584

8685
- Fixes get last insert id for pgsql
8786
- Add data validation custom message parser
@@ -95,7 +94,7 @@ References
9594

9695
## 5.0.5 - 2023-05-20
9796

98-
Release 5.0.5
97+
Release **5.0.5**
9998

10099
- Fix migration status table definition
101100
- Fix enum creation for pgsql
@@ -104,7 +103,7 @@ Reference #232
104103

105104
## 5.0.4 - 2023-05-19
106105

107-
Release 5.0.4
106+
Release **5.0.4**
108107

109108
- Fixes HTTP Client
110109
- Add variable binding to the env loader
@@ -124,7 +123,7 @@ Add many fixes
124123

125124
## 5.0.2 - 2023-05-16
126125

127-
Release for 5.0.2
126+
Release **5.0.2**
128127

129128
- Fix action dependency injector
130129
- Add the base error handler

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"scripts": {
6969
"phpcbf": "phpcbf --standard=psr12 --severity=4 --tab-width=4 src tests",
7070
"phpcs": "phpcs --standard=psr12 --severity=4 --tab-width=4 src",
71-
"test": "phpunit --configuration phpunit.dist.xml"
71+
"test": "phpunit --configuration phpunit.dist.xml",
72+
"testdox": "phpunit --configuration phpunit.dist.xml --testdox"
7273
}
7374
}

docker-compose.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,39 @@ services:
127127
interval: 10s
128128
timeout: 5s
129129
retries: 5
130+
rabbitmq:
131+
container_name: bowphp_rabbitmq
132+
image: rabbitmq:3.11-management
133+
restart: unless-stopped
134+
ports:
135+
- "5672:5672"
136+
- "15672:15672"
137+
environment:
138+
RABBITMQ_DEFAULT_USER: guest
139+
RABBITMQ_DEFAULT_PASS: guest
140+
networks:
141+
- bowphp_network
142+
healthcheck:
143+
test: ["CMD", "rabbitmq-diagnostics", "ping"]
144+
interval: 10s
145+
timeout: 5s
146+
retries: 5
147+
minio:
148+
container_name: bowphp_minio
149+
image: minio/minio
150+
restart: unless-stopped
151+
ports:
152+
- "9000:9000"
153+
- "9001:9001"
154+
environment:
155+
MINIO_ROOT_USER: minioadmin
156+
MINIO_ROOT_PASSWORD: minioadmin
157+
command: server /data --console-address ":9001"
158+
networks:
159+
- bowphp_network
160+
healthcheck:
161+
test: ["CMD", "mc", "alias", "set", "local", "http://localhost:9000", "minioadmin", "minioadmin"]
162+
interval: 10s
163+
timeout: 5s
164+
retries: 5
165+

src/Cache/Adapters/FilesystemAdapter.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@ private function makeHashFilename(string $key, bool $make_group_directory = fals
7373

7474
$group = Str::slice($hash, 0, 2);
7575

76-
if ($make_group_directory) {
77-
if (!is_dir($this->directory . '/' . $group)) {
78-
@mkdir($this->directory . '/' . $group);
79-
}
76+
if ($make_group_directory && !is_dir($this->directory . '/' . $group)) {
77+
@mkdir($this->directory . '/' . $group);
8078
}
8179

8280
return $this->directory . '/' . $group . '/' . $hash;
@@ -153,22 +151,15 @@ public function get(string $key, mixed $default = null): mixed
153151
{
154152
if (!$this->has($key)) {
155153
$this->with_meta = false;
156-
157-
if (is_callable($default)) {
158-
return $default();
159-
}
160-
161-
return $default;
154+
return is_callable($default) ? $default() : $default;
162155
}
163156

164157
$cache = unserialize(file_get_contents($this->makeHashFilename($key)));
165158

166159
$expire_at = $cache['__bow_meta']['expire_at'];
167160

168-
if ($expire_at != '+') {
169-
if (time() > $expire_at) {
170-
return null;
171-
}
161+
if ($expire_at != '+' && time() > $expire_at) {
162+
return null;
172163
}
173164

174165
if (!$this->with_meta) {

src/Cache/Cache.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Bow\Cache\Adapters\DatabaseAdapter;
1010
use Bow\Cache\Adapters\FilesystemAdapter;
1111
use Bow\Cache\Adapters\RedisAdapter;
12-
use ErrorException;
1312
use InvalidArgumentException;
1413

1514
class Cache
@@ -86,12 +85,12 @@ public static function store(string $store): CacheAdapterInterface
8685
* Get the cache instance
8786
*
8887
* @return CacheAdapterInterface
89-
* @throws ErrorException
88+
* @throws CacheException
9089
*/
9190
public static function getInstance(): CacheAdapterInterface
9291
{
9392
if (is_null(static::$instance)) {
94-
throw new ErrorException("Unable to get cache instance before configuration");
93+
throw new CacheException("Unable to get cache instance before configuration");
9594
}
9695

9796
return static::$instance;
@@ -122,7 +121,7 @@ public static function addAdapters(array $adapters): void
122121
public static function __callStatic(string $name, array $arguments)
123122
{
124123
if (is_null(static::$instance)) {
125-
throw new ErrorException(
124+
throw new CacheException(
126125
"Unable to get cache instance before configuration"
127126
);
128127
}

src/Cache/CacheException.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Bow\Cache;
4+
5+
class CacheException extends \Exception
6+
{
7+
}

src/Console/Command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Bow\Console\Command\Generator\GenerateServiceCommand;
2121
use Bow\Console\Command\Generator\GenerateSessionCommand;
2222
use Bow\Console\Command\Generator\GenerateAppEventCommand;
23-
use Bow\Console\Command\Generator\GenerateProducerCommand;
23+
use Bow\Console\Command\Generator\GenerateWorkerCommand;
2424
use Bow\Console\Command\Generator\GenerateExceptionCommand;
2525
use Bow\Console\Command\Generator\GenerateMessagingCommand;
2626
use Bow\Console\Command\Generator\GenerateMigrationCommand;
@@ -57,7 +57,7 @@ class Command extends AbstractCommand
5757
"add:validation" => GenerateValidationCommand::class,
5858
"add:event" => GenerateAppEventCommand::class,
5959
"add:listener" => GenerateEventListenerCommand::class,
60-
"add:producer" => GenerateProducerCommand::class,
60+
"add:producer" => GenerateWorkerCommand::class,
6161
"add:command" => GenerateConsoleCommand::class,
6262
"add:message" => GenerateMessagingCommand::class,
6363
"run:console" => ReplCommand::class,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bow\Console\Command\Generator;
6+
7+
use Bow\Console\AbstractCommand;
8+
use Bow\Console\Color;
9+
use Bow\Console\Generator;
10+
11+
class GenerateJobCommand extends AbstractCommand
12+
{
13+
/**
14+
* Add job
15+
*
16+
* @param string $job
17+
* @return void
18+
*/
19+
public function run(string $job): void
20+
{
21+
$generator = new Generator(
22+
$this->setting->getJobDirectory(),
23+
$job
24+
);
25+
26+
if ($generator->fileExists()) {
27+
echo Color::red("The job already exists");
28+
exit(1);
29+
}
30+
31+
$generator->write('job', [
32+
'baseNamespace' => $this->namespaces['job'] ?? 'App\\Jobs'
33+
]);
34+
35+
echo Color::green("The job has been well created.");
36+
exit(0);
37+
}
38+
}

src/Console/Command/Generator/GenerateProducerCommand.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)