Skip to content

Commit

Permalink
build(test): begin rewrite tests from scratch using pest (#86)
Browse files Browse the repository at this point in the history
* dev(lint): compat php 7.3+
* build: add uggo script to download latest illuminate/foundation
* chore(vendor): update Foundation to 8.26.1
* build(test): begin rewrite tests from scratch using pest
* fix(test-helpers): avoid arrow function for php 7.3 compat
  • Loading branch information
QWp6t committed Feb 4, 2021
1 parent 1667d78 commit d8a4d14
Show file tree
Hide file tree
Showing 71 changed files with 425 additions and 1,754 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Expand Up @@ -46,4 +46,4 @@ jobs:
run: composer run-script lint

- name: Execute the Composer test script
run: composer run-script lint
run: composer run-script test
10 changes: 6 additions & 4 deletions composer.json
Expand Up @@ -58,12 +58,14 @@
"vlucas/phpdotenv": "^5.2"
},
"require-dev": {
"brain/monkey": "^2.6",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"filp/whoops": "^2.9",
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.4",
"pestphp/pest": "^1.0",
"phpcompatibility/php-compatibility": "^9.3",
"phpunit/phpunit": "^8.5.8|^9.3.3",
"roave/security-advisories": "dev-master",
"spatie/temporary-directory": "^1.3",
"squizlabs/php_codesniffer": "^3.5"
},
"suggest": {
Expand All @@ -77,7 +79,7 @@
"scripts": {
"lint": "phpcs",
"lint:fix": "phpcbf",
"test": "phpunit",
"coverage": "phpunit --coverage-html coverage"
"test": "pest",
"coverage": "pest --coverage --coverage-html=coverage"
}
}
4 changes: 2 additions & 2 deletions phpcs.xml.dist
Expand Up @@ -12,8 +12,8 @@
<exclude-pattern>src/Illuminate/*</exclude-pattern>
</rule>

<!-- Support for PHP 7.2+ -->
<config name="testVersion" value="7.2-"/>
<!-- Support for PHP 7.3+ -->
<config name="testVersion" value="7.3-"/>

<file>acorn.php</file>
<file>src</file>
Expand Down
26 changes: 12 additions & 14 deletions phpunit.xml.dist
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
Expand All @@ -10,21 +12,17 @@
stopOnFailure="false">
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">./tests/Feature</directory>
<directory suffix="Test.php">./tests/Unit</directory>
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./</directory>
<exclude>
<directory suffix=".blade.php">./</directory>
<directory>./config</directory>
<directory>./vendor</directory>
<directory>./tests</directory>
</exclude>
</whitelist>
</filter>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./src/Illuminate/*</directory>
</exclude>
</coverage>
<php>
<env name="WP_ENV" value="testing"/>
</php>
Expand Down
35 changes: 35 additions & 0 deletions scripts/download-latest-laravel.sh
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -e

# pro tip: maybe don't run this script. i mostly just hacked my way through this. this should definitely not be automated in any way.

# thx u https://explainshell.com/

# YOINK! https://stackoverflow.com/a/4774063
SCRIPTS_DIR="$(cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"

TEMP_DIR="${SCRIPTS_DIR}/.temp"

LARAVEL_VERSION=$(curl --silent "https://api.github.com/repos/laravel/framework/tags" | jq -r '.[].name' | sort | tail -1)

ARCHIVE_FILE="${LARAVEL_VERSION}.tar.gz"

rm -rf "${TEMP_DIR}"
mkdir -p "${TEMP_DIR}"

wget -q "https://github.com/laravel/framework/archive/${ARCHIVE_FILE}" -O "${TEMP_DIR}/${ARCHIVE_FILE}"

ROOT_FOLDER=$(tar ztf "${TEMP_DIR}/${ARCHIVE_FILE}" | sort | head -1)

pushd "${TEMP_DIR}"

# only extracts the Foundation folder
tar xzf "${TEMP_DIR}/${ARCHIVE_FILE}" "${ROOT_FOLDER}src/Illuminate/Foundation" --strip-components=4 --one-top-level=Foundation

popd

# only syncs files that already exist in the destination
rsync -a --existing "${TEMP_DIR}/Foundation/" "${SCRIPTS_DIR}/../src/Illuminate/Foundation/"

rm -rf "${TEMP_DIR}"
Empty file modified src/Illuminate/Foundation/AliasLoader.php 100644 → 100755
Empty file.
40 changes: 35 additions & 5 deletions src/Illuminate/Foundation/Application.php 100644 → 100755
Expand Up @@ -33,7 +33,7 @@ class Application extends Container implements ApplicationContract, CachesConfig
*
* @var string
*/
const VERSION = '8.22.1';
const VERSION = '8.26.1';

/**
* The base path for the Laravel installation.
Expand Down Expand Up @@ -112,6 +112,13 @@ class Application extends Container implements ApplicationContract, CachesConfig
*/
protected $databasePath;

/**
* The custom language file path defined by the developer.
*
* @var string
*/
protected $langPath;

/**
* The custom storage path defined by the developer.
*
Expand Down Expand Up @@ -407,7 +414,30 @@ public function useDatabasePath($path)
*/
public function langPath()
{
return $this->resourcePath().DIRECTORY_SEPARATOR.'lang';
if ($this->langPath) {
return $this->langPath;
}

if (is_dir($path = $this->resourcePath().DIRECTORY_SEPARATOR.'lang')) {
return $path;
}

return $this->basePath().DIRECTORY_SEPARATOR.'lang';
}

/**
* Set the language file directory.
*
* @param string $path
* @return $this
*/
public function useLangPath($path)
{
$this->langPath = $path;

$this->instance('path.lang', $path);

return $this;
}

/**
Expand Down Expand Up @@ -530,7 +560,7 @@ public function environment(...$environments)
}

/**
* Determine if application is in local environment.
* Determine if the application is in the local environment.
*
* @return bool
*/
Expand All @@ -540,7 +570,7 @@ public function isLocal()
}

/**
* Determine if application is in production environment.
* Determine if the application is in the production environment.
*
* @return bool
*/
Expand Down Expand Up @@ -1230,7 +1260,7 @@ public function setFallbackLocale($fallbackLocale)
}

/**
* Determine if application locale is the given locale.
* Determine if the application locale is the given locale.
*
* @param string $locale
* @return bool
Expand Down
14 changes: 13 additions & 1 deletion src/Illuminate/Foundation/Exceptions/Handler.php
Expand Up @@ -11,6 +11,8 @@
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\MultipleRecordsFoundException;
use Illuminate\Database\RecordsNotFoundException;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
Expand All @@ -19,7 +21,6 @@
use Illuminate\Session\TokenMismatchException;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Reflector;
use Illuminate\Support\Traits\ReflectsClosures;
use Illuminate\Support\ViewErrorBag;
Expand All @@ -28,6 +29,13 @@
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
use Symfony\Component\HttpFoundation\RedirectResponse as SymfonyRedirectResponse;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;
use Whoops\Handler\HandlerInterface;
use Whoops\Run as Whoops;
Expand Down Expand Up @@ -82,6 +90,8 @@ class Handler implements ExceptionHandlerContract
HttpException::class,
HttpResponseException::class,
ModelNotFoundException::class,
MultipleRecordsFoundException::class,
RecordsNotFoundException::class,
SuspiciousOperationException::class,
TokenMismatchException::class,
ValidationException::class,
Expand Down Expand Up @@ -362,6 +372,8 @@ protected function prepareException(Throwable $e)
$e = new HttpException(419, $e->getMessage(), $e);
} elseif ($e instanceof SuspiciousOperationException) {
$e = new NotFoundHttpException('Bad hostname provided.', $e);
} elseif ($e instanceof RecordsNotFoundException) {
$e = new NotFoundHttpException('Not found.', $e);
}

return $e;
Expand Down
Empty file modified src/Illuminate/Foundation/Exceptions/ReportableHandler.php 100755 → 100644
Empty file.
Empty file modified src/Illuminate/Foundation/ProviderRepository.php 100644 → 100755
Empty file.
27 changes: 1 addition & 26 deletions src/Roots/Acorn/Application.php
Expand Up @@ -190,31 +190,6 @@ public function useConfigPath($path)
return $this;
}

/**
* Get the path to the language files.
*
* @return string
*/
public function langPath()
{
return $this->langPath ?: $this->resourcePath('lang');
}

/**
* Set the path to the language files.
*
* @param string $path
* @return $this
*/
public function useLangPath($path)
{
$this->langPath = $path;

$this->instance('path.lang', $path);

return $this;
}

/**
* Get the path to the public / web directory.
*
Expand Down Expand Up @@ -286,7 +261,7 @@ protected function registerBaseServiceProviders()
*/
public function isDownForMaintenance()
{
return is_file($this->storagePath() . '/framework/down') || is_file(ABSPATH . '/.maintenance');
return is_file($this->storagePath() . '/framework/down') || (defined('ABSPATH') && is_file(constant('ABSPATH') . '/.maintenance'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Roots/Acorn/Filesystem/Filesystem.php
Expand Up @@ -83,7 +83,7 @@ public function getRelativePath($basePath, $targetPath)
$path = str_repeat('../', count($sourceDirs)) . implode('/', $targetDirs);

return $path === '' || $path[0] === '/'
|| ($colonPos = strpos($path, ':')) !== false && (($slashPos = strpos($path, '/') >= $colonPos)
|| ($colonPos = strpos($path, ':')) !== false && ($colonPos < ($slashPos = strpos($path, '/'))
|| $slashPos === false)
? "./$path" : $path;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/Application/AliasLoaderTest.php
@@ -0,0 +1,19 @@
<?php

use Roots\Acorn\AliasLoader;

it('should load global function aliases', function () {
$loader = AliasLoader::getInstance([]);

expect(function_exists('app'))->toBeFalse();
expect(function_exists('asset'))->toBeFalse();
expect(function_exists('config'))->toBeFalse();
expect(function_exists('view'))->toBeFalse();

$loader->register();

expect(function_exists('app'))->toBeTrue();
expect(function_exists('asset'))->toBeTrue();
expect(function_exists('config'))->toBeTrue();
expect(function_exists('view'))->toBeTrue();
});

0 comments on commit d8a4d14

Please sign in to comment.