Skip to content

Commit 1fac27a

Browse files
author
Tint Naing Win
authored
Merge pull request #1 from thettunaung-carro/test/add-test-cases
feat: add test cases
2 parents 93c195a + e6e272c commit 1fac27a

File tree

12 files changed

+503
-27
lines changed

12 files changed

+503
-27
lines changed

.github/workflows/run-tests.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Run tests
2+
on:
3+
push:
4+
paths:
5+
- "**.php"
6+
- "phpunit.xml"
7+
- "composer.json"
8+
- "composer.lock"
9+
10+
jobs:
11+
pest:
12+
name: Run tests
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out repository code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: 8.2
22+
tools: composer:v2
23+
coverage: none
24+
25+
- name: Install composer dependencies
26+
uses: nick-fields/retry@v2
27+
with:
28+
timeout_minutes: 3
29+
max_attempts: 5
30+
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
31+
32+
- name: Run pest
33+
timeout-minutes: 2
34+
run: ./vendor/bin/pest

README.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,29 @@ php ./vendor/bin/vapor-ignore init
2626

2727
### vapor-ignore.yml
2828

29-
#### `ignore` directive
29+
#### `ignore` directive
30+
3031
Ignore the specified file or directory.
3132

3233
#### `vendor` directive
34+
3335
Ignore the specified file or directory from the `vendor` directory.
3436

35-
- readme - Ignore the `readme.md` file from the `vendor` directory.
36-
- changelog - Ignore the `changelog.md` file from the `vendor` directory.
37-
- contributing - Ignore the `contributing.md` file from the `vendor` directory.
38-
- upgrade - Ignore the `upgrade.md` file from the `vendor` directory.
39-
- tests - Ignore the `tests` directory from the `vendor` directory.
40-
- security - Ignore the `security.md` file from the `vendor` directory.
41-
- license - Ignore the `license.md` file from the `vendor` directory.
42-
- laravel-idea - Ignore the `laravel-idea` directory from the `vendor` directory.
43-
- .github - Ignore the `.github` directory from the `vendor` directory.
44-
- dotfiles - Ignore the dotfiles(`.editorconfig`, `.gitignore`, `.gitattributes` and `.php_cs.dist.php`) from the `vendor` directory.
37+
- readme - Ignore the `readme.md` file from the `vendor` directory.
38+
- changelog - Ignore the `changelog.md` file from the `vendor` directory.
39+
- contributing - Ignore the `contributing.md` file from the `vendor` directory.
40+
- upgrade - Ignore the `upgrade.md` file from the `vendor` directory.
41+
- tests - Ignore the `tests` directory from the `vendor` directory.
42+
- security - Ignore the `security.md` file from the `vendor` directory.
43+
- license - Ignore the `license.md` file from the `vendor` directory.
44+
- laravel-idea - Ignore the `laravel-idea` directory from the `vendor` directory.
45+
- .github - Ignore the `.github` directory from the `vendor` directory.
46+
- dotfiles - Ignore the dotfiles(`.editorconfig`, `.gitignore`, `.gitattributes` and `.php_cs.dist.php`) from the `vendor` directory.
47+
48+
## Testing
49+
```bash
50+
composer test
51+
```
4552

4653
## Changelog
4754

@@ -57,8 +64,8 @@ Please review [our security policy](../../security/policy) on how to report secu
5764

5865
## Credits
5966

60-
- [Tint Naing Win](https://github.com/tintnaingwinn)
61-
- [All Contributors](../../contributors)
67+
- [Tint Naing Win](https://github.com/tintnaingwinn)
68+
- [All Contributors](../../contributors)
6269

6370
## License
6471

composer.json

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
{
22
"name": "ageekdev/vapor-ignore",
3+
"version": "1.1.0",
34
"description": "To clean unnecessary files for Laravel Vapor deployment",
45
"keywords": [
5-
"laravel", "vapor-ignore", "vapor", "deployment", "serverless", "laravel-vapor", "ignore"
6+
"laravel",
7+
"vapor-ignore",
8+
"vapor",
9+
"deployment",
10+
"serverless",
11+
"laravel-vapor",
12+
"ignore"
613
],
714
"homepage": "https://github.com/ageekdev/vapor-ignore",
815
"license": "MIT",
@@ -22,29 +29,40 @@
2229
"laravel/vapor-cli": "^1.40"
2330
},
2431
"require-dev": {
25-
"laravel/pint": "^1.10",
2632
"larastan/larastan": "^2.4.1",
33+
"laravel/pint": "^1.10",
2734
"orchestra/testbench": "^7.0|^8.0|^9.0",
35+
"pestphp/pest": "^2.34",
2836
"phpstan/extension-installer": "^1.1",
2937
"phpstan/phpstan-deprecation-rules": "^1.0",
3038
"roave/security-advisories": "dev-latest"
3139
},
3240
"autoload": {
3341
"psr-4": {
3442
"AgeekDev\\VaporIgnore\\": "src/"
43+
},
44+
"files": [
45+
"src/helpers.php"
46+
]
47+
},
48+
"autoload-dev": {
49+
"psr-4": {
50+
"Tests\\": "tests"
3551
}
3652
},
3753
"scripts": {
3854
"analyse": "vendor/bin/phpstan analyse",
39-
"format": "vendor/bin/pint"
55+
"format": "vendor/bin/pint",
56+
"test": "vendor/bin/pest"
4057
},
4158
"config": {
4259
"sort-packages": true,
4360
"optimize-autoloader": true,
4461
"allow-plugins": {
45-
"phpstan/extension-installer": true
62+
"phpstan/extension-installer": true,
63+
"pestphp/pest-plugin": true
4664
}
4765
},
4866
"minimum-stability": "dev",
4967
"prefer-stable": true
50-
}
68+
}

phpunit.xml.dist

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
>
7+
<testsuites>
8+
<testsuite name="Test Suite">
9+
<directory suffix="Test.php">./tests</directory>
10+
</testsuite>
11+
</testsuites>
12+
<source>
13+
<include>
14+
<directory suffix=".php">./app</directory>
15+
<directory suffix=".php">./src</directory>
16+
</include>
17+
</source>
18+
</phpunit>

src/Manifest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,20 @@ public static function isIgnoredVendor(string $name): bool
4747
/**
4848
* Write a fresh manifest file.
4949
*/
50-
public static function init(): void
50+
public static function init(array $configuration = []): void
5151
{
52-
static::freshConfiguration();
52+
static::createFreshManifestFile($configuration);
5353
}
5454

5555
/**
5656
* Write a fresh vapor-ignore manifest file.
5757
*/
58-
protected static function freshConfiguration(): void
58+
protected static function createFreshManifestFile(array $configuration = []): void
59+
{
60+
static::write($configuration ?: static::freshConfiguration());
61+
}
62+
63+
public static function freshConfiguration(): array
5964
{
6065
$vendor = [
6166
'readme' => true,
@@ -74,10 +79,10 @@ protected static function freshConfiguration(): void
7479
'/tests',
7580
];
7681

77-
static::write([
82+
return [
7883
'vendor' => $vendor,
7984
'ignore' => $ignore,
80-
]);
85+
];
8186
}
8287

8388
/**

src/helpers.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
if (! function_exists('getPackageName')) {
4+
function getPackageName(): string
5+
{
6+
return 'Vapor Ignore';
7+
}
8+
}
9+
10+
if (! function_exists('getPackageVersion')) {
11+
function getPackageVersion(): string
12+
{
13+
return Composer\InstalledVersions::getRootPackage()['pretty_version'];
14+
}
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use AgeekDev\VaporIgnore\Commands\CleanIgnoredFilesCommand;
4+
use AgeekDev\VaporIgnore\Manifest;
5+
use AgeekDev\VaporIgnore\Path;
6+
use Symfony\Component\Console\Tester\CommandTester;
7+
use Tests\TestCase;
8+
9+
use function PHPUnit\Framework\assertFileDoesNotExist;
10+
use function PHPUnit\Framework\assertStringContainsString;
11+
12+
it('can run clean:ignored-files command', function (): void {
13+
Manifest::init([
14+
'vendor' => [],
15+
]);
16+
17+
/**
18+
* @var TestCase $this
19+
*/
20+
$command = $this->resolveCommand(CleanIgnoredFilesCommand::class);
21+
22+
$tester = new CommandTester($command);
23+
24+
$tester->execute([
25+
'command' => $command->getName(),
26+
]);
27+
28+
$tester->assertCommandIsSuccessful();
29+
30+
assertFileDoesNotExist(Path::defaultManifest());
31+
32+
assertStringContainsString('Total Removed Files Size:', $tester->getDisplay());
33+
});

tests/Feature/InitCommandTest.php

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
3+
use AgeekDev\VaporIgnore\Commands\InitCommand;
4+
use AgeekDev\VaporIgnore\Manifest;
5+
use AgeekDev\VaporIgnore\Path;
6+
use Symfony\Component\Console\Tester\CommandTester;
7+
use Symfony\Component\Yaml\Yaml;
8+
use Tests\TestCase;
9+
10+
use function PHPUnit\Framework\assertFileExists;
11+
use function PHPUnit\Framework\assertStringMatchesFormatFile;
12+
13+
it('can run init command', function (): void {
14+
/**
15+
* @var TestCase $this
16+
*/
17+
$command = $this->resolveCommand(InitCommand::class);
18+
19+
$tester = new CommandTester($command);
20+
21+
$tester->setInputs([
22+
'no',
23+
]);
24+
25+
$tester->execute([
26+
'command' => $command->getName(),
27+
]);
28+
29+
assertInitCommandRunPorperly($tester, Path::defaultManifest(), Yaml::dump(Manifest::freshConfiguration()));
30+
});
31+
32+
it('can run init command with force option', function (): void {
33+
touch(Path::defaultManifest());
34+
35+
/**
36+
* @var TestCase $this
37+
*/
38+
$command = $this->resolveCommand(InitCommand::class);
39+
40+
$tester = new CommandTester($command);
41+
42+
$tester->setInputs([
43+
'no',
44+
]);
45+
46+
$tester->execute([
47+
'command' => $command->getName(),
48+
'--force' => true,
49+
]);
50+
51+
assertInitCommandRunPorperly($tester, Path::defaultManifest(), Yaml::dump(Manifest::freshConfiguration()));
52+
});
53+
54+
it('can run init command and override', function (): void {
55+
touch(Path::defaultManifest());
56+
57+
/**
58+
* @var TestCase $this
59+
*/
60+
$command = $this->resolveCommand(InitCommand::class);
61+
62+
$tester = new CommandTester($command);
63+
64+
$tester->setInputs([
65+
'yes',
66+
'no',
67+
]);
68+
69+
$tester->execute([
70+
'command' => $command->getName(),
71+
]);
72+
73+
assertInitCommandRunPorperly($tester, Path::defaultManifest(), Yaml::dump(Manifest::freshConfiguration()));
74+
});
75+
76+
it('can run init command with custom manifest', function (): void {
77+
$customManifest = getcwd().'/vapor-ignore-test.yml';
78+
79+
/**
80+
* @var TestCase $this
81+
*/
82+
$command = $this->resolveCommand(InitCommand::class);
83+
84+
$tester = new CommandTester($command);
85+
86+
$tester->setInputs([
87+
'no',
88+
]);
89+
90+
$tester->execute([
91+
'command' => $command->getName(),
92+
'--manifest' => $customManifest,
93+
]);
94+
95+
assertInitCommandRunPorperly($tester, $customManifest, Yaml::dump(Manifest::freshConfiguration()));
96+
97+
removeFile($customManifest);
98+
});
99+
100+
it('can run init command and add clean command', function (): void {
101+
createVaporManifest();
102+
103+
/**
104+
* @var TestCase $this
105+
*/
106+
$command = $this->resolveCommand(InitCommand::class);
107+
108+
$tester = new CommandTester($command);
109+
110+
$tester->setInputs([
111+
'yes',
112+
]);
113+
114+
$tester->execute([
115+
'command' => $command->getName(),
116+
]);
117+
118+
assertInitCommandRunPorperly($tester, Path::defaultManifest(), Yaml::dump(Manifest::freshConfiguration()));
119+
120+
assertFileExists($vaporPath = Path::vaporManifest());
121+
122+
assertStringMatchesFormatFile($vaporPath, vaporManifestContentWithCleanCommand());
123+
});
124+
125+
function assertInitCommandRunPorperly(CommandTester $tester, string $path, string $format): void
126+
{
127+
$tester->assertCommandIsSuccessful();
128+
129+
assertFileExists($path);
130+
131+
assertStringMatchesFormatFile($path, $format);
132+
}

0 commit comments

Comments
 (0)