mirror of
https://github.com/bitinflow/bunny-cli.git
synced 2026-03-13 13:45:54 +00:00
first commit
This commit is contained in:
16
.editorconfig
Normal file
16
.editorconfig
Normal file
@@ -0,0 +1,16 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.yml]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
7
.gitattributes
vendored
Normal file
7
.gitattributes
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
* text=auto
|
||||
/.github export-ignore
|
||||
.styleci.yml export-ignore
|
||||
.scrutinizer.yml export-ignore
|
||||
BACKERS.md export-ignore
|
||||
CONTRIBUTING.md export-ignore
|
||||
CHANGELOG.md export-ignore
|
||||
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/example
|
||||
/vendor
|
||||
/.idea
|
||||
/.vscode
|
||||
/.vagrant
|
||||
.phpunit.result.cache
|
||||
.env
|
||||
201
LICENSE
Normal file
201
LICENSE
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2021 René Preuß
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
21
README.md
Normal file
21
README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Bunny CLI
|
||||
|
||||
Replicate and storage your files to the edge storage of bunny.net.
|
||||
|
||||
Bunny CLI is not affiliated with BunnyWay d.o.o.
|
||||
|
||||
------
|
||||
|
||||
## Documentation
|
||||
|
||||
For full documentation, visit [laravel-zero.com](https://laravel-zero.com/).
|
||||
|
||||
## Support the development
|
||||
|
||||
**Do you like this project? Support it by donating**
|
||||
|
||||
- Patreon: [Donate](https://patreon.com/ghostzero)
|
||||
|
||||
## License
|
||||
|
||||
Laravel Zero is an open-source software licensed under the Apache 2.0 license.
|
||||
40
app/Bunny/Client.php
Normal file
40
app/Bunny/Client.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Bunny;
|
||||
|
||||
use GuzzleHttp\RequestOptions;
|
||||
|
||||
class Client
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new \GuzzleHttp\Client([
|
||||
'base_uri' => 'https://api.bunny.net/',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getPullZone(int $pullZoneId): Result
|
||||
{
|
||||
return $this->request('GET', "pullzone/{$pullZoneId}", [
|
||||
RequestOptions::HEADERS => [
|
||||
'AccessKey' => config('bunny.api.access_key'),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function purgeCache(int $pullZoneId): Result
|
||||
{
|
||||
return $this->request('POST', "pullzone/{$pullZoneId}/purgeCache", [
|
||||
RequestOptions::HEADERS => [
|
||||
'AccessKey' => config('bunny.api.access_key'),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
private function request(string $method, string $uri, array $options): Result
|
||||
{
|
||||
$response = $this->client->request($method, $uri, $options);
|
||||
|
||||
return new Result($response);
|
||||
}
|
||||
}
|
||||
31
app/Bunny/Filesystem/EdgeFile.php
Normal file
31
app/Bunny/Filesystem/EdgeFile.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Bunny\Filesystem;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use stdClass;
|
||||
|
||||
class EdgeFile implements File
|
||||
{
|
||||
private stdClass $file;
|
||||
|
||||
public function __construct(stdClass $file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
public function getFilename($search = '', $replace = ''): string
|
||||
{
|
||||
return Str::replaceFirst($search, $replace, $this->file->Path . $this->file->ObjectName);
|
||||
}
|
||||
|
||||
public function isDirectory(): bool
|
||||
{
|
||||
return $this->file->IsDirectory;
|
||||
}
|
||||
|
||||
public function getChecksum(): string
|
||||
{
|
||||
return $this->file->Checksum;
|
||||
}
|
||||
}
|
||||
94
app/Bunny/Filesystem/EdgeStorage.php
Normal file
94
app/Bunny/Filesystem/EdgeStorage.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Bunny\Filesystem;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Promise\PromiseInterface;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Illuminate\Support\Str;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class EdgeStorage
|
||||
{
|
||||
private Client $client;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new Client([
|
||||
'base_uri' => sprintf('https://%s', config('bunny.storage.hostname')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function allFiles(string $path, &$results = array())
|
||||
{
|
||||
$promise = $this->client->getAsync(self::normalizePath($path, true), [
|
||||
RequestOptions::HEADERS => [
|
||||
'AccessKey' => config('bunny.storage.password'),
|
||||
],
|
||||
]);
|
||||
|
||||
$promise->then(
|
||||
function (ResponseInterface $res) use (&$results) {
|
||||
$files = array_map(
|
||||
fn($file) => new EdgeFile($file),
|
||||
json_decode($res->getBody()->getContents(), false)
|
||||
);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$results[] = $file;
|
||||
if ($file->isDirectory()) {
|
||||
$this->allFiles($file->getFilename(), $results);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
function (RequestException $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
echo $e->getRequest()->getMethod();
|
||||
}
|
||||
);
|
||||
|
||||
$promise->wait();
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function put(LocalFile $file, string $local, string $edge): PromiseInterface
|
||||
{
|
||||
return $this->client->putAsync(self::normalizePath($file->getFilename($local, $edge), $file->isDirectory()), [
|
||||
RequestOptions::HEADERS => [
|
||||
'AccessKey' => config('bunny.storage.password'),
|
||||
'Checksum' => $file->getChecksum(),
|
||||
],
|
||||
RequestOptions::BODY => fopen($file->getFilename(), 'r'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete(EdgeFile $file): PromiseInterface
|
||||
{
|
||||
return $this->client->deleteAsync(self::normalizePath($file->getFilename(), $file->isDirectory()), [
|
||||
RequestOptions::HEADERS => [
|
||||
'AccessKey' => config('bunny.storage.password'),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function getClient(): Client
|
||||
{
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
private static function normalizePath(string $filename, bool $isDirectory): string
|
||||
{
|
||||
if (!Str::startsWith($filename, ['/'])) {
|
||||
$filename = '/' . $filename;
|
||||
}
|
||||
|
||||
if ($isDirectory && !Str::endsWith($filename, ['/'])) {
|
||||
$filename = $filename . '/';
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
}
|
||||
12
app/Bunny/Filesystem/File.php
Normal file
12
app/Bunny/Filesystem/File.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Bunny\Filesystem;
|
||||
|
||||
interface File
|
||||
{
|
||||
public function getFilename($search = '', $replace = ''): string;
|
||||
|
||||
public function getChecksum(): string;
|
||||
|
||||
public function isDirectory(): bool;
|
||||
}
|
||||
141
app/Bunny/Filesystem/FileCompare.php
Normal file
141
app/Bunny/Filesystem/FileCompare.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace App\Bunny\Filesystem;
|
||||
|
||||
use App\Bunny\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Pool;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class FileCompare
|
||||
{
|
||||
private const RESERVED_FILENAMES = [];
|
||||
|
||||
private LocalStorage $localStorage;
|
||||
private EdgeStorage $edgeStorage;
|
||||
private Command $output;
|
||||
|
||||
public function __construct(LocalStorage $localStorage, EdgeStorage $edgeStorage, Command $output)
|
||||
{
|
||||
$this->localStorage = $localStorage;
|
||||
$this->edgeStorage = $edgeStorage;
|
||||
$this->apiClient = new Client();
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
public function compare(string $local, string $edge): void
|
||||
{
|
||||
$this->output->info('- Hashing files...');
|
||||
$localFiles = $this->localStorage->allFiles($local);
|
||||
$this->output->info(sprintf('✔ Finished hashing %s files', count($localFiles)));
|
||||
$this->output->info('- CDN diffing files...');
|
||||
$edgeFiles = $this->edgeStorage->allFiles($edge);
|
||||
|
||||
$requests = [];
|
||||
|
||||
/** @var LocalFile $localFile */
|
||||
foreach ($localFiles as $localFile) {
|
||||
if ($localFile->isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filename = $localFile->getFilename($local);
|
||||
if ($match = $this->contains($edgeFiles, $filename, $edge)) {
|
||||
if ($match->getChecksum() != $localFile->getChecksum()) {
|
||||
$requests[] = fn() => $this->edgeStorage->put($localFile, $local, $edge);
|
||||
}
|
||||
} else {
|
||||
$requests[] = fn() => $this->edgeStorage->put($localFile, $local, $edge);
|
||||
}
|
||||
}
|
||||
|
||||
/** @var EdgeFile $edgeFile */
|
||||
foreach ($edgeFiles as $edgeFile) {
|
||||
$filename = $edgeFile->getFilename($edge);
|
||||
if (!$this->contains($localFiles, $filename, $local) && !$this->isReserved($filename)) {
|
||||
$requests[] = fn() => $this->edgeStorage->delete($edgeFile);
|
||||
}
|
||||
}
|
||||
|
||||
$this->output->info(sprintf('✔ CDN requesting %s files', $count = count($requests)));
|
||||
|
||||
if ($count > 0) {
|
||||
$this->output->info(sprintf('- Synchronizing %s files', $count));
|
||||
|
||||
$bar = $this->output->getOutput()->createProgressBar($count);
|
||||
|
||||
$pool = new Pool($this->edgeStorage->getClient(), $requests, [
|
||||
'concurrency' => 5,
|
||||
'fulfilled' => function (Response $response, $index) use ($bar) {
|
||||
$bar->advance();
|
||||
},
|
||||
'rejected' => function (RequestException $reason, $index) use ($bar) {
|
||||
$bar->advance();
|
||||
|
||||
if ($this->rejectedDue404Deletion($reason)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->output->warn(sprintf(
|
||||
'Request rejected by bunny.net. Status: %s, Message: %s',
|
||||
$reason->getResponse()->getStatusCode(),
|
||||
$reason->getMessage()
|
||||
));
|
||||
},
|
||||
]);
|
||||
|
||||
// Initiate the transfers and create a promise
|
||||
$promise = $pool->promise();
|
||||
|
||||
$bar->start();
|
||||
$promise->wait(); // Force the pool of requests to complete.
|
||||
$bar->finish();
|
||||
|
||||
$this->output->newLine();
|
||||
|
||||
$this->output->info(sprintf('✔ Finished synchronizing %s files', $count));
|
||||
}
|
||||
|
||||
$this->output->info('- Waiting for deploy to go live...');
|
||||
|
||||
$result = $this->apiClient->purgeCache($pullZoneId = config('bunny.pull_zone.id'));
|
||||
|
||||
if (!$result->success()) {
|
||||
$this->output->info('✔ Deploy is live (without flush)!');
|
||||
return;
|
||||
}
|
||||
|
||||
$result = $this->apiClient->getPullZone($pullZoneId);
|
||||
|
||||
$this->output->info('✔ Deploy is live!');
|
||||
$this->output->newLine();
|
||||
|
||||
foreach ($result->getData()->Hostnames as $hostname) {
|
||||
$schema = ($hostname->ForceSSL || $hostname->HasCertificate) ? 'https' : 'http';
|
||||
$this->output->info(sprintf('Website URL: %s://%s', $schema, $hostname->Value));
|
||||
}
|
||||
}
|
||||
|
||||
private function contains(array $files, string $filename, string $search): ?File
|
||||
{
|
||||
foreach ($files as $edgeFile) {
|
||||
if ($edgeFile->getFilename($search) === $filename) {
|
||||
return $edgeFile;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function isReserved($filename): bool
|
||||
{
|
||||
return in_array($filename, self::RESERVED_FILENAMES);
|
||||
}
|
||||
|
||||
private function rejectedDue404Deletion(RequestException $reason): bool
|
||||
{
|
||||
return $reason->getRequest()->getMethod() === 'DELETE'
|
||||
&& in_array($reason->getResponse()->getStatusCode(), [404, 400, 500], true);
|
||||
}
|
||||
}
|
||||
32
app/Bunny/Filesystem/LocalFile.php
Normal file
32
app/Bunny/Filesystem/LocalFile.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Bunny\Filesystem;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class LocalFile implements File
|
||||
{
|
||||
private string $filename;
|
||||
private ?string $checksum;
|
||||
|
||||
public function __construct(string $filename, ?string $checksum)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
$this->checksum = $checksum;
|
||||
}
|
||||
|
||||
public function getFilename($search = '', $replace = ''): string
|
||||
{
|
||||
return Str::replaceFirst($search, $replace, $this->filename);
|
||||
}
|
||||
|
||||
public function getChecksum(): string
|
||||
{
|
||||
return $this->checksum;
|
||||
}
|
||||
|
||||
public function isDirectory(): bool
|
||||
{
|
||||
return $this->checksum == null;
|
||||
}
|
||||
}
|
||||
23
app/Bunny/Filesystem/LocalStorage.php
Normal file
23
app/Bunny/Filesystem/LocalStorage.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Bunny\Filesystem;
|
||||
|
||||
class LocalStorage
|
||||
{
|
||||
function allFiles($dir, &$results = array())
|
||||
{
|
||||
$files = scandir($dir);
|
||||
|
||||
foreach ($files as $value) {
|
||||
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
|
||||
if (!is_dir($path)) {
|
||||
$results[] = new LocalFile($path, strtoupper(hash_file('sha256', $path)));
|
||||
} else if ($value != "." && $value != "..") {
|
||||
$results[] = new LocalFile($path, null);
|
||||
$this->allFiles($path, $results);
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
30
app/Bunny/Result.php
Normal file
30
app/Bunny/Result.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Bunny;
|
||||
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class Result
|
||||
{
|
||||
private ResponseInterface $response;
|
||||
|
||||
private $data;
|
||||
|
||||
public function __construct(ResponseInterface $response)
|
||||
{
|
||||
$this->response = $response;
|
||||
$this->data = json_decode($this->response->getBody()->getContents(), false);
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function success(): bool
|
||||
{
|
||||
return in_array(floor($this->response->getStatusCode() / 100), [2]);
|
||||
}
|
||||
}
|
||||
0
app/Commands/.gitkeep
Normal file
0
app/Commands/.gitkeep
Normal file
64
app/Commands/DeployCommand.php
Normal file
64
app/Commands/DeployCommand.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Bunny\Filesystem\EdgeStorage;
|
||||
use App\Bunny\Filesystem\FileCompare;
|
||||
use App\Bunny\Filesystem\LocalStorage;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use LaravelZero\Framework\Commands\Command;
|
||||
|
||||
class DeployCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The signature of the command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'deploy
|
||||
{--dir=dist : Root directory to upload}';
|
||||
|
||||
/**
|
||||
* The description of the command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Deploy dist folder to edge storage';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$edgeStorage = new EdgeStorage();
|
||||
$localStorage = new LocalStorage();
|
||||
$fileCompare = new FileCompare($localStorage, $edgeStorage, $this);
|
||||
|
||||
$localPath = realpath($path = $this->option('dir') ?? 'dist');
|
||||
|
||||
if (!file_exists($localPath) || !is_dir($localPath)) {
|
||||
$this->warn(sprintf('The directory %s does not exists.', $path));
|
||||
return 1;
|
||||
}
|
||||
|
||||
$edgePath = sprintf('/%s', config('bunny.storage.username'));
|
||||
|
||||
$fileCompare->compare($localPath, $edgePath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Define the command's schedule.
|
||||
*
|
||||
* @param Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
public function schedule(Schedule $schedule): void
|
||||
{
|
||||
// $schedule->command(static::class)->everyMinute();
|
||||
}
|
||||
}
|
||||
33
app/Providers/AppServiceProvider.php
Normal file
33
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\FtpAdapter;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use League\Flysystem\Filesystem;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Storage::extend('ftp', function ($app, $config) {
|
||||
return new Filesystem(new FtpAdapter($config));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
50
bootstrap/app.php
Normal file
50
bootstrap/app.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Create The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The first thing we will do is create a new Laravel application instance
|
||||
| which serves as the "glue" for all the components of Laravel, and is
|
||||
| the IoC container for the system binding all of the various parts.
|
||||
|
|
||||
*/
|
||||
|
||||
$app = new LaravelZero\Framework\Application(
|
||||
dirname(__DIR__)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bind Important Interfaces
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Next, we need to bind some important interfaces into the container so
|
||||
| we will be able to resolve them when needed. The kernels serve the
|
||||
| incoming requests to this application from both the web and CLI.
|
||||
|
|
||||
*/
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Console\Kernel::class,
|
||||
LaravelZero\Framework\Kernel::class
|
||||
);
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Debug\ExceptionHandler::class,
|
||||
Illuminate\Foundation\Exceptions\Handler::class
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Return The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This script returns the application instance. The instance is given to
|
||||
| the calling script so we can separate the building of the instances
|
||||
| from the actual running of the application and sending responses.
|
||||
|
|
||||
*/
|
||||
|
||||
return $app;
|
||||
18
box.json
Normal file
18
box.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"chmod": "0755",
|
||||
"directories": [
|
||||
"app",
|
||||
"bootstrap",
|
||||
"config",
|
||||
"vendor"
|
||||
],
|
||||
"files": [
|
||||
"composer.json"
|
||||
],
|
||||
"exclude-composer-files": false,
|
||||
"compression": "GZ",
|
||||
"compactors": [
|
||||
"KevinGH\\Box\\Compactor\\Php",
|
||||
"KevinGH\\Box\\Compactor\\Json"
|
||||
]
|
||||
}
|
||||
BIN
builds/bunny
Executable file
BIN
builds/bunny
Executable file
Binary file not shown.
53
bunny
Executable file
53
bunny
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
define('LARAVEL_START', microtime(true));
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register The Auto Loader
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Composer provides a convenient, automatically generated class loader
|
||||
| for our application. We just need to utilize it! We'll require it
|
||||
| into the script here so that we do not have to worry about the
|
||||
| loading of any our classes "manually". Feels great to relax.
|
||||
|
|
||||
*/
|
||||
|
||||
$autoloader = require file_exists(__DIR__.'/vendor/autoload.php') ? __DIR__.'/vendor/autoload.php' : __DIR__.'/../../autoload.php';
|
||||
|
||||
$app = require_once __DIR__.'/bootstrap/app.php';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Run The Artisan Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When we run the console application, the current CLI command will be
|
||||
| executed in this console and the response sent back to a terminal
|
||||
| or another output device for the developers. Here goes nothing!
|
||||
|
|
||||
*/
|
||||
|
||||
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
|
||||
|
||||
$status = $kernel->handle(
|
||||
$input = new Symfony\Component\Console\Input\ArgvInput,
|
||||
new Symfony\Component\Console\Output\ConsoleOutput
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Shutdown The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Once Artisan has finished running, we will fire off the shutdown events
|
||||
| so that any final work may be done by the application before we shut
|
||||
| down the process. This is the last thing to happen to the request.
|
||||
|
|
||||
*/
|
||||
|
||||
$kernel->terminate($input, $status);
|
||||
|
||||
exit($status);
|
||||
48
composer.json
Normal file
48
composer.json
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "ghostzero/bunny",
|
||||
"description": "The Laravel Zero Framework.",
|
||||
"keywords": ["bunny", "cdn", "console", "cli"],
|
||||
"homepage": "https://github.com/ghostzero/bunny-cli",
|
||||
"type": "project",
|
||||
"license": "Apache-2.0",
|
||||
"support": {
|
||||
"issues": "https://github.com/ghostzero/bunny-cli/issues",
|
||||
"source": "https://github.com/ghostzero/bunny-cli"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "René Preuß",
|
||||
"email": "rene@preuss.io"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.4|^8.0",
|
||||
"ext-json": "*",
|
||||
"guzzlehttp/guzzle": "^7.0",
|
||||
"laminas/laminas-text": "^2.8",
|
||||
"laravel-zero/framework": "^8.8",
|
||||
"laravel-zero/phar-updater": "^1.0.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.4.3",
|
||||
"pestphp/pest": "^1.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "app/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"preferred-install": "dist",
|
||||
"sort-packages": true,
|
||||
"optimize-autoloader": true
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"bin": ["builds/bunny"]
|
||||
}
|
||||
6781
composer.lock
generated
Normal file
6781
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
60
config/app.php
Normal file
60
config/app.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value is the name of your application. This value is used when the
|
||||
| framework needs to place the application's name in a notification or
|
||||
| any other location as required by the application or its packages.
|
||||
|
|
||||
*/
|
||||
|
||||
'name' => 'Bunny.net',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Version
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the "version" your application is currently running
|
||||
| in. You may want to follow the "Semantic Versioning" - Given a version
|
||||
| number MAJOR.MINOR.PATCH when an update happens: https://semver.org.
|
||||
|
|
||||
*/
|
||||
|
||||
'version' => app('git.version'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Environment
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the "environment" your application is currently
|
||||
| running in. This may determine how you prefer to configure various
|
||||
| services the application utilizes. This can be overridden using
|
||||
| the global command line "--env" option when calling commands.
|
||||
|
|
||||
*/
|
||||
|
||||
'env' => 'development',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Autoloaded Service Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The service providers listed here will be automatically loaded on the
|
||||
| request to your application. Feel free to add your own services to
|
||||
| this array to grant expanded functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => [
|
||||
App\Providers\AppServiceProvider::class,
|
||||
],
|
||||
|
||||
];
|
||||
15
config/bunny.php
Normal file
15
config/bunny.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'storage' => [
|
||||
'hostname' => env('BUNNY_STORAGE_HOSTNAME'),
|
||||
'username' => env('BUNNY_STORAGE_USERNAME'),
|
||||
'password' => env('BUNNY_STORAGE_PASSWORD'),
|
||||
],
|
||||
'pull_zone' => [
|
||||
'id' => env('BUNNY_PULL_ZONE_ID'),
|
||||
],
|
||||
'api' => [
|
||||
'access_key' => env('BUNNY_API_ACCESS_KEY'),
|
||||
],
|
||||
];
|
||||
80
config/commands.php
Normal file
80
config/commands.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Command
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Laravel Zero will always run the command specified below when no command name is
|
||||
| provided. Consider update the default command for single command applications.
|
||||
| You cannot pass arguments to the default command because they are ignored.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => NunoMaduro\LaravelConsoleSummary\SummaryCommand::class,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Commands Paths
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the "paths" that should be loaded by the console's
|
||||
| kernel. Foreach "path" present on the array provided below the kernel
|
||||
| will extract all "Illuminate\Console\Command" based class commands.
|
||||
|
|
||||
*/
|
||||
|
||||
'paths' => [app_path('Commands')],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Added Commands
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You may want to include a single command class without having to load an
|
||||
| entire folder. Here you can specify which commands should be added to
|
||||
| your list of commands. The console's kernel will try to load them.
|
||||
|
|
||||
*/
|
||||
|
||||
'add' => [
|
||||
// ..
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Hidden Commands
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Your application commands will always be visible on the application list
|
||||
| of commands. But you can still make them "hidden" specifying an array
|
||||
| of commands below. All "hidden" commands can still be run/executed.
|
||||
|
|
||||
*/
|
||||
|
||||
'hidden' => [
|
||||
NunoMaduro\LaravelConsoleSummary\SummaryCommand::class,
|
||||
Symfony\Component\Console\Command\HelpCommand::class,
|
||||
Illuminate\Console\Scheduling\ScheduleRunCommand::class,
|
||||
Illuminate\Console\Scheduling\ScheduleFinishCommand::class,
|
||||
Illuminate\Foundation\Console\VendorPublishCommand::class,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Removed Commands
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Do you have a service provider that loads a list of commands that
|
||||
| you don't need? No problem. Laravel Zero allows you to specify
|
||||
| below a list of commands that you don't to see in your app.
|
||||
|
|
||||
*/
|
||||
|
||||
'remove' => [
|
||||
// ..
|
||||
],
|
||||
|
||||
];
|
||||
84
config/logo.php
Normal file
84
config/logo.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Enabled
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines if the app name should be represented as an
|
||||
| ASCII logo. This file provides a sane default location for all
|
||||
| information concerning the logo and is display customization.
|
||||
|
|
||||
*/
|
||||
|
||||
'enabled' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Logo Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the text that is rendered for the logo.
|
||||
| It defaults to the app name, but it can be any other text
|
||||
| value if the logo should be different to the app name.
|
||||
|
|
||||
*/
|
||||
'name' => config('app.name'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Font
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the font which should be used for rendering.
|
||||
| By default, one default font is shipped. However, you are free
|
||||
| to download and use additional fonts: http://www.figlet.org.
|
||||
|
|
||||
*/
|
||||
|
||||
'font' => \LaravelZero\Framework\Components\Logo\FigletString::DEFAULT_FONT,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Output Width
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the maximum width of the output string. This is
|
||||
| used for word-wrap as well as justification. Be careful when using
|
||||
| small values, because they may result in an undefined behavior.
|
||||
|
|
||||
*/
|
||||
|
||||
'outputWidth' => 80,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Justification
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the justification of the logo text. By default,
|
||||
| justification is provided, which will work well on most of your
|
||||
| console apps. Of course, you are free to change this value.
|
||||
|
|
||||
*/
|
||||
|
||||
'justification' => null,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Right To Left
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the option in which the text is written. By, default
|
||||
| the setting of the font-file is used. When justification is not defined,
|
||||
| a text written from right-to-left is automatically right-aligned.
|
||||
|
|
||||
| Possible values: "right-to-left", "left-to-right", null
|
||||
|
|
||||
*/
|
||||
|
||||
'rightToLeft' => null,
|
||||
|
||||
];
|
||||
20
config/updater.php
Normal file
20
config/updater.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use LaravelZero\Framework\Components\Updater\Strategy\GithubStrategy;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Self-updater Strategy
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify which update strategy class you wish to use when
|
||||
| updating your application via the "self-update" command. This must
|
||||
| be a class that implements the StrategyInterface from Humbug.
|
||||
|
|
||||
*/
|
||||
|
||||
'strategy' => GithubStrategy::class,
|
||||
|
||||
];
|
||||
24
phpunit.xml.dist
Normal file
24
phpunit.xml.dist
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false">
|
||||
<testsuites>
|
||||
<testsuite name="Feature">
|
||||
<directory suffix="Test.php">./tests/Feature</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Unit">
|
||||
<directory suffix="Test.php">./tests/Unit</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">./app</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
</phpunit>
|
||||
22
tests/CreatesApplication.php
Normal file
22
tests/CreatesApplication.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
|
||||
trait CreatesApplication
|
||||
{
|
||||
/**
|
||||
* Creates the application.
|
||||
*
|
||||
* @return \Illuminate\Foundation\Application
|
||||
*/
|
||||
public function createApplication()
|
||||
{
|
||||
$app = require __DIR__.'/../bootstrap/app.php';
|
||||
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
|
||||
return $app;
|
||||
}
|
||||
}
|
||||
7
tests/Feature/InspiringCommandTest.php
Executable file
7
tests/Feature/InspiringCommandTest.php
Executable file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
test('inspiring command', function () {
|
||||
$this->artisan('inspiring')
|
||||
->expectsOutput('Simplicity is the ultimate sophistication.')
|
||||
->assertExitCode(0);
|
||||
});
|
||||
45
tests/Pest.php
Normal file
45
tests/Pest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Test Case
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The closure you provide to your test functions is always bound to a specific PHPUnit test
|
||||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
|
||||
| need to change it using the "uses()" function to bind a different classes or traits.
|
||||
|
|
||||
*/
|
||||
|
||||
uses(Tests\TestCase::class)->in('Feature');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Expectations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When you're writing tests, you often need to check that values meet certain conditions. The
|
||||
| "expect()" function gives you access to a set of "expectations" methods that you can use
|
||||
| to assert different things. Of course, you may extend the Expectation API at any time.
|
||||
|
|
||||
*/
|
||||
|
||||
expect()->extend('toBeOne', function () {
|
||||
return $this->toBe(1);
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
|
||||
| project that you don't want to repeat in every file. Here you can also expose helpers as
|
||||
| global functions to help you to reduce the number of lines of code in your test files.
|
||||
|
|
||||
*/
|
||||
|
||||
function something()
|
||||
{
|
||||
// ..
|
||||
}
|
||||
10
tests/TestCase.php
Normal file
10
tests/TestCase.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use LaravelZero\Framework\Testing\TestCase as BaseTestCase;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
use CreatesApplication;
|
||||
}
|
||||
5
tests/Unit/ExampleTest.php
Normal file
5
tests/Unit/ExampleTest.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
test('example', function () {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
Reference in New Issue
Block a user