Skip to content

Commit fe41265

Browse files
authored
Merge pull request #28 from apple-x-co/test
Add test
2 parents 00eaf42 + 09506b3 commit fe41265

24 files changed

+470
-79
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,13 @@ jobs:
1212

1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v3
1616

1717
- name: Setup PHP
1818
uses: shivammathur/setup-php@v2
1919
with:
2020
php-version: '5.4'
2121

22-
# - name: Setup PHP
23-
# uses: shivammathur/setup-php@v2
24-
# with:
25-
# php-version: '7.4'
26-
#
27-
# - name: Get composer cache directory
28-
# id: composer-cache
29-
# run: echo "::set-output name=dir::$(composer config cache-files-dir)"
30-
#
31-
# - name: Cache dependencies
32-
# uses: actions/cache@v2
33-
# with:
34-
# path: ${{ steps.composer-cache.outputs.dir }}
35-
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
36-
# restore-keys: ${{ runner.os }}-composer-
37-
#
38-
# - name: Install dependencies
39-
# run: composer install --no-interaction --no-progress --prefer-dist
40-
4122
- name: Download latest phar-composer.phar
4223
run: composer run-script download-phar-composer
4324

.github/workflows/tests.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- '**.md'
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
name: All tests
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
operating-system:
18+
- ubuntu-latest
19+
php-version:
20+
- '5.4'
21+
- '5.6'
22+
- '7.0'
23+
- '7.1'
24+
- '7.2'
25+
- '7.3'
26+
- '8.0'
27+
- '8.1'
28+
- '8.2'
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v3
32+
33+
- name: Setup PHP
34+
uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: ${{ matrix.php-version }}
37+
extensions: mbstring
38+
tools: composer
39+
coverage: none
40+
41+
- name: Get composer cache directory
42+
id: composer-cache
43+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
44+
45+
- name: Cache dependencies
46+
uses: actions/cache@v3
47+
with:
48+
path: ${{ steps.composer-cache.outputs.dir }}
49+
key: ${{ runner.os }}-php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.lock') }}
50+
restore-keys: ${{ runner.os }}-php${{ matrix.php-version }}-composer-
51+
52+
- name: Unset platform.php
53+
run: composer config --unset platform.php
54+
55+
- name: Install dependencies
56+
run: composer install --no-interaction --no-progress --prefer-dist
57+
58+
- name: Run tests
59+
run: composer run-script test

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ composer.lock
1313
/build/
1414
phar-composer.phar
1515
rocket.phar
16+
/phpunit.xml
17+
/.phpunit.result.cache
18+
/.phpcs-cache
19+
/.phpunit.cache

README.md

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,71 @@
22

33
## Requirement
44

5-
* PHP 5.4+
5+
* PHP version 5.4.0 or greater.
66

77
## Installation
88

99
```bash
10+
# Download using wget
1011
wget https://github.com/apple-x-co/rocket/releases/latest/download/rocket.phar
12+
13+
# Then test the downloaded phars
1114
chmod u+x rocket.phar
1215
./rocket.phar --init > ./rocket.json
1316
```
1417

15-
## Information
18+
## Usage
19+
20+
### Show information
1621

1722
```bash
1823
./rocket.phar --info #--no-color
1924
```
2025

21-
## Update
26+
### Verification configure file
2227

2328
```bash
24-
./rocket.phar --upgrade
29+
./rocket.phar --config ./rocket.json --verify
2530
```
2631

27-
## Usage
32+
### Slack notification test
2833

2934
```bash
30-
# slack notification test
3135
./rocket.phar --config ./rocket.json --notify-test
36+
```
3237

33-
# verify rocket.json
34-
./rocket.phar --config ./rocket.json --verify
38+
### Dry run sync directory
3539

36-
# dry run (default)
40+
```bash
3741
./rocket.phar --config ./rocket.json --sync dry
42+
```
3843

39-
# git pull & sync confirm
44+
### Git pull & Confirm sync directory
45+
46+
```bash
4047
./rocket.phar --config ./rocket.json --git pull --sync confirm
48+
```
4149

42-
# git pull & sync force (crontab)
50+
### Git pull & Force sync directory
51+
52+
```bash
4353
./rocket.phar --config ./rocket.json --git pull --sync force
54+
```
55+
56+
### Sync directory only
4457

45-
# not git
58+
```bash
4659
./rocket.phar --config ./rocket.json --sync confirm
60+
```
61+
62+
### Slack notification
4763

48-
# notify
49-
cat example.txt | ./rocket.phar --config ./rocket.json --notify
64+
```bash
65+
echo "HELLO WORLD" | ./rocket.phar --config ./rocket.json --notify
66+
```
67+
68+
### Download latest version rocket
69+
70+
```bash
71+
./rocket.phar --upgrade
5072
```

bin/build.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
passthru('
44
rm -rf build && mkdir build
55
cp -r bin src composer.json build/ && rm build/bin/build.php &&
6-
composer config -d build/ platform.php 5.6 &&
7-
composer install -d build/ --no-dev &&
6+
composer install -d build/ --no-interaction --no-progress --prefer-dist --no-dev &&
87
php -d phar.readonly=off ./phar-composer.phar build build/ &&
98
php ./rocket.phar --info --no-color
109
', $code);

bin/rocket.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
require dirname(__DIR__) . '/vendor/autoload.php';
44

5-
use Rocket\Options;
65
use Rocket\Main;
6+
use Rocket\Options;
77

88
date_default_timezone_set('Asia/Tokyo');
9+
mb_internal_encoding('UTF-8');
910

1011
$options = new Options();
1112

composer.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,33 @@
1111
"bin/rocket.php"
1212
],
1313
"require": {
14-
"php": "^5.4",
14+
"php": "^5.4 || ^7.0 || ^8.0",
1515
"ext-curl": "*",
1616
"ext-json": "*",
1717
"ext-posix": "*",
1818
"ext-zip": "*"
1919
},
20+
"require-dev": {
21+
"phpunit/phpunit": "*"
22+
},
2023
"autoload": {
2124
"psr-4": {
2225
"Rocket\\": "src/"
26+
},
27+
"files": [
28+
"src/Polyfill/bootstrap.php"
29+
]
30+
},
31+
"autoload-dev": {
32+
"psr-4": {
33+
"Rocket\\": "tests/"
2334
}
2435
},
2536
"scripts": {
2637
"information": "@php rocket.phar --info --no-color",
2738
"download-phar-composer": "curl --silent --show-error --location https://clue.engineering/phar-composer-latest.phar --output phar-composer.phar",
28-
"build": "@php bin/build.php"
39+
"build": "@php bin/build.php",
40+
"test": "./vendor/bin/phpunit"
2941
},
3042
"config": {
3143
"sort-packages": true,

docker/compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
web:
3+
image: ghcr.io/buddying-inc/webserver-centos83:apache24-php74
4+
container_name: rocket
5+
working_dir: /var/www/vhosts/localhost
6+
volumes:
7+
- type: bind
8+
source: ../
9+
target: /var/www/vhosts/localhost
10+
consistency: delegated
11+
ports:
12+
- target: 80
13+
published: 80
14+
protocol: tcp
15+
mode: host
16+
environment:
17+
- PHP_XDEBUG=off
18+
- COMPOSER_ALLOW_SUPERUSER=1

docker/docker-discard.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
cd "$(dirname "$0")" || exit
4+
5+
count=$(docker compose ps -q | awk 'END{print NR}')
6+
7+
if [ "$count" == "0" ]; then
8+
echo "Docker is already discarded !!"
9+
else
10+
docker compose down -v
11+
fi

docker/docker-startup.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
cd "$(dirname "$0")" || exit
4+
5+
count=$(docker ps | sed -n '2,50p' | grep -v 'Exit ' | awk 'END{print NR}')
6+
7+
if [ "$count" == "0" ]; then
8+
docker compose up -d
9+
else
10+
echo "Docker is already running !!"
11+
echo "=="
12+
docker ps
13+
fi

phpunit.xml.dist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<phpunit bootstrap="./vendor/autoload.php">
3+
<testsuites>
4+
<testsuite name="My Project - TestSuite">
5+
<directory>./tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
</phpunit>

src/Chunker.php

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,14 @@ class Chunker
66
{
77
/**
88
* @param string $text
9-
* @param int $length
9+
* @param int $chunkSize
1010
*
1111
* @return array<string>
1212
*/
13-
public function __invoke($text, $length)
13+
public function __invoke($text, $chunkSize)
1414
{
15-
$chunks = [];
16-
$buf = null;
15+
$chunks = mb_str_split($text, $chunkSize, 'UTF-8');
1716

18-
$lines = explode(PHP_EOL, $text);
19-
foreach ($lines as $line) {
20-
if (strlen($line) >= $length) {
21-
foreach (str_split($line, $length) as $chunk) {
22-
$chunks[] = $chunk;
23-
}
24-
25-
continue;
26-
}
27-
28-
$line .= PHP_EOL;
29-
30-
if (strlen($buf . $line) > $length) {
31-
$chunks[] = $buf;
32-
$buf = null;
33-
}
34-
35-
$buf .= $line;
36-
}
37-
38-
if ($buf !== null) {
39-
$chunks[] = $buf;
40-
}
41-
42-
return $chunks;
17+
return is_array($chunks) ? $chunks : [];
4318
}
4419
}

src/EscapeSequence.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class EscapeSequence
4040
'cyan' => self::FOREGROUND_CYAN,
4141
'magenta' => self::FOREGROUND_MAGENTA,
4242
'bg-white' => self::BACKGROUND_WHITE,
43+
'bg-black' => self::BACKGROUND_BLACK,
4344
];
4445

4546
private static $OPTIONS = [

0 commit comments

Comments
 (0)