Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ concurrency:
cancel-in-progress: true

jobs:
sniff:
lint:
runs-on: ubuntu-latest
name: Sniff
name: Lint

steps:
- name: Checkout code
Expand All @@ -37,7 +37,7 @@ jobs:
uses: ramsey/composer-install@v3

- name: Analyze source code
run: composer sniff
run: composer lint

analyze:
runs-on: ubuntu-latest
Expand All @@ -59,7 +59,7 @@ jobs:
run: composer analyze

test:
needs: [sniff, analyze]
needs: [lint, analyze]
runs-on: ubuntu-latest
name: Test

Expand All @@ -83,5 +83,15 @@ jobs:
- name: Install PHP dependencies
uses: ramsey/composer-install@v3

- name: Run test
- name: Install bashunit
run: |
curl -s https://bashunit.typeddevs.com/install.sh > install.sh
chmod +x install.sh
./install.sh

- name: Run PHPUnit test
run: composer test

- name: Run bashunit test
if: matrix.machine != 'windows-latest'
run: ./lib/bashunit ./tests/bashunit/*.sh
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"scripts": {
"analyze": "phpstan",
"format": "phpcbf",
"sniff": "phpcs",
"lint": "phpcs",
"test": "phpunit"
},
"config": {
Expand Down
29 changes: 29 additions & 0 deletions tests/bashunit/test_eq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# @data_provider data_equal
function test_equal() {
bin/version eq $1 $2 2>&1
local exit_code=$?

assert_equals 0 $exit_code;
}

# @data_provider data_not_equal
function test_not_equal() {
bin/version eq $1 $2 2>&1
local exit_code=$?

assert_equals 1 $exit_code;
}

function data_not_equal() {
echo "1.0.0" "1.0.1";
echo "v2.0.0" "v2.1.0";
echo "3.5.2-alpha.1" "3.5.2-alpha.2";
}

function data_equal() {
echo "1.0.0" "1.0.0";
echo "v2.0.0" "v2.0.0";
echo "3.5.1-alpha.1" "3.5.1-alpha.1";
echo "4.0.0-beta.2+1" "4.0.0-beta.2+2"; # Build metadata should not affect equality.
echo "4.2.0-beta.2+1" "4.2.0-beta.2+1";
}
28 changes: 28 additions & 0 deletions tests/bashunit/test_gt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# @data_provider data_greater_than
function test_greater_than() {
bin/version gt $1 $2 2>&1
local exit_code=$?

assert_equals 0 $exit_code;
}

# @data_provider data_not_greater_than
function test_not_greater_than() {
bin/version gt $1 $2 2>&1
local exit_code=$?

assert_equals 1 $exit_code;
}

function data_not_greater_than() {
echo "1.0.0" "1.0.0"; # Equal.
echo "v2.0.0" "v2.1.0"; # Less than.
echo "3.5.2-alpha.1" "3.5.2-alpha.2"; # Less than with pre-release.
echo "3.5.2-alpha.2+2" "3.5.2-alpha.2+1";
}

function data_greater_than() {
echo "1.0.1" "1.0.0"; # Greater than.
echo "v2.1.0" "v2.0.0"; # Greater than with prefix.
echo "3.5.2-alpha.2" "3.5.2-alpha.1"; # Greater than with pre-release.
}
60 changes: 60 additions & 0 deletions tests/bashunit/test_increment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# @data_provider data_increment_patch
function test_increment_patch() {
ver=$(bin/version increment $1);
assert_equals $ver $2;
}

# @data_provider data_increment_minor
function test_increment_minor() {
ver=$(bin/version increment $1 --part minor);
assert_equals $ver $2;
}

# @data_provider data_increment_major
function test_increment_major() {
ver=$(bin/version increment $1 --part major);
assert_equals $ver $2;
}

# @data_provider data_increment_with_pre_release
function test_increment_with_pre_release() {
ver=$(bin/version increment $1 --pre alpha);
assert_equals $ver $2;
}

# @data_provider data_increment_with_build
function test_increment_with_build() {
ver=$(bin/version increment $1 --build 123);
assert_equals $ver $2;
}

# @data_provider data_increment_with_pre_release_and_build
function test_increment_with_pre_release_and_build() {
ver=$(bin/version increment $1 --build 123 --pre alpha);
assert_equals $ver $2;
}

function data_increment_patch() {
echo "0.0.0" "0.0.1";
echo "1.0.0" "1.0.1";
}

function data_increment_minor() {
echo "0.0.0" "0.1.0";
echo "1.0.0" "1.1.0";
}

function data_increment_major() {
echo "0.0.0" "1.0.0";
echo "1.0.0" "2.0.0";
}

function data_increment_with_pre_release() {
echo "0.0.0" "0.0.1-alpha";
echo "1.0.0" "1.0.1-alpha";
}

function data_increment_with_pre_release_and_build() {
echo "0.0.0" "0.0.1-alpha+123";
echo "1.0.0" "1.0.1-alpha+123";
}
27 changes: 27 additions & 0 deletions tests/bashunit/test_lt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# @data_provider data_less_than
function test_less_than() {
bin/version lt $1 $2 2>&1
local exit_code=$?

assert_equals 0 $exit_code;
}

# @data_provider data_not_less_than
function test_not_less_than() {
bin/version lt $1 $2 2>&1
local exit_code=$?

assert_equals 1 $exit_code;
}

function data_less_than() {
echo "1.0.0" "1.0.1";
echo "v2.0.0" "v2.1.0";
echo "3.5.2-alpha.1" "3.5.2-alpha.2";
}

function data_not_less_than() {
echo "1.0.0" "1.0.0"; # Equal.
echo "v2.0.0" "v1.0.0"; # Greater than.
echo "3.5.1-alpha.2" "3.5.1-alpha.1"; # Greater than with pre-release.
}
32 changes: 32 additions & 0 deletions tests/bashunit/test_validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# @data_provider data_valid
function test_equal() {
bin/version validate $1 2>&1
local exit_code=$?

assert_equals 0 $exit_code;
}

# @data_provider data_invalid
function test_invalid() {
bin/version validate $1 2>&1
local exit_code=$?

assert_equals 1 $exit_code;
}

function data_valid() {
echo "1.0.0"
echo "v1.0.0"
echo "2.1.7-alpha"
echo "1.0.0-beta.1"
echo "3.4.5+build.78"
echo "0.9.1-alpha.1+exp.sha.5114f85"
}

function data_invalid() {
echo "0"
echo "0.0"
echo "v"
echo "v0"
echo "v0.0"
}
2 changes: 2 additions & 0 deletions tests/phpunit/Commands/ValidateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function testValidVersionArgument(string $version): void

public static function dataInvalidVersionArgument(): iterable
{
yield ['0'];
yield ['0.0'];
yield ['v'];
yield ['v0'];
yield ['v0.0'];
Expand Down