Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #25 from devuri/add/tests/httpkernel
Browse files Browse the repository at this point in the history
Add/tests/httpkernel
  • Loading branch information
devuri authored Jul 31, 2022
2 parents 5e4811d + 5861c58 commit 05a0a97
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 49 deletions.
22 changes: 9 additions & 13 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
WP_HOME=http://localhost
WP_SITEURL=http://localhost
WP_HOME='https://example.com'
WP_SITEURL="${WP_HOME}/wp"

DB_NAME=
DB_USER=root
DB_PASSWORD=
DB_NAME='wordpress-testdb'
DB_USER='root'
DB_PASSWORD='password'
DB_HOST=127.0.0.1
DB_PREFIX=
DB_PREFIX='wp_test_'

WP_ENVIRONMENT_TYPE=production
WP_ENVIRONMENT_TYPE='development'

DEVELOPERADMIN=

UPLOAD_DIR=uploads

MEMORY_LIMIT=256M
MAX_MEMORY_LIMIT=256M
MEMORY_LIMIT='256M'
MAX_MEMORY_LIMIT='256M'

AUTH_KEY=
SECURE_AUTH_KEY=
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"psalm": "vendor/bin/psalm",
"psalm-secure": "vendor/bin/psalm --taint-analysis",
"psalm-info": "vendor/bin/psalm --show-info=true",
"psalm-fix-return": "vendor/bin/psalm --alter --issues=MissingReturnType",
"psalm-autofix": [
"composer install -q",
"vendor/bin/psalm --alter --issues=InvalidNullableReturnType,MismatchingDocblockReturnType,InvalidReturnType,InvalidFalsableReturnType,LessSpecificReturnType,MissingParamType"
Expand Down
12 changes: 11 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="ENVIRONMENT" value="test"/>
<!-- WordPress env constants -->
<env name="FAKE_APP_DIR_PATH" value="/srv/users/dev/apps/example"/>
<env name="WP_HOME" value="https://example.com"/>
<env name="WP_SITEURL" value="https://example.com/wp"/>
<env name="DB_NAME" value="wordpress_testdb"/>
<env name="DB_USER" value="root"/>
<env name="DB_PASSWORD" value="password"/>
<env name="DB_HOST" value="127.0.0.1"/>
<env name="DB_PREFIX" value="wp_test_" />
<env name="WP_ENVIRONMENT_TYPE" value="development"/>
</php>
</phpunit>
67 changes: 53 additions & 14 deletions src/App/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
*/
class HttpKernel
{
protected $app_path = null;
protected $app_path = null;
protected static $list = [];
protected $args;

public function __construct( string $app_path, $args = [] )
Expand All @@ -22,6 +23,16 @@ public function __construct( string $app_path, $args = [] )
$this->args = $args;
}

public function get_app_path(): string
{
return $this->app_path;
}

public function get_args(): array
{
return $this->args;
}

/**
* Start the app.
*
Expand All @@ -30,7 +41,7 @@ public function __construct( string $app_path, $args = [] )
*/
public function init( string $env_type = 'production', $constants = true ): void
{
Setup::init( $this->app_path )->config( $env_type );
Setup::init( $this->get_app_path() )->config( $env_type );

if ( true === $constants ) {
$this->constants();
Expand All @@ -49,32 +60,60 @@ public function init( string $env_type = 'production', $constants = true ): void
public function constants(): void
{
// define app_path.
\define( 'APP_PATH', $this->app_path );
$this->define( 'APP_PATH', $this->get_app_path() );

// define public web root dir.
\define( 'PUBLIC_WEB_DIR', APP_PATH . '/public' );
$this->define( 'PUBLIC_WEB_DIR', APP_PATH . '/public' );

// wp dir path
$this->define( 'WP_DIR_PATH', PUBLIC_WEB_DIR . '/wp' );

// define assets dir.
\define( 'APP_ASSETS_DIR', PUBLIC_WEB_DIR . '/assets' );
$this->define( 'APP_ASSETS_DIR', PUBLIC_WEB_DIR . '/assets' );

// Disable any kind of automatic upgrade.
// this will be handled via composer.
\define( 'AUTOMATIC_UPDATER_DISABLED', true );
$this->define( 'AUTOMATIC_UPDATER_DISABLED', true );

// Directory PATH.
\define( 'APP_CONTENT_DIR', '/content' );
\define( 'WP_CONTENT_DIR', PUBLIC_WEB_DIR . APP_CONTENT_DIR );
$this->define( 'APP_CONTENT_DIR', '/content' );
$this->define( 'WP_CONTENT_DIR', PUBLIC_WEB_DIR . APP_CONTENT_DIR );

// Content Directory.
\define( 'CONTENT_DIR', APP_CONTENT_DIR );
\define( 'WP_CONTENT_URL', env( 'WP_HOME' ) . CONTENT_DIR );
$this->define( 'CONTENT_DIR', APP_CONTENT_DIR );
$this->define( 'WP_CONTENT_URL', env( 'WP_HOME' ) . CONTENT_DIR );

// Plugins.
\define( 'WP_PLUGIN_DIR', PUBLIC_WEB_DIR . '/plugins' );
\define( 'WP_PLUGIN_URL', env( 'WP_HOME' ) . '/plugins' );
$this->define( 'WP_PLUGIN_DIR', PUBLIC_WEB_DIR . '/plugins' );
$this->define( 'WP_PLUGIN_URL', env( 'WP_HOME' ) . '/plugins' );

// Must-Use Plugins.
\define( 'WPMU_PLUGIN_DIR', PUBLIC_WEB_DIR . '/mu-plugins' );
\define( 'WPMU_PLUGIN_URL', env( 'WP_HOME' ) . '/mu-plugins' );
$this->define( 'WPMU_PLUGIN_DIR', PUBLIC_WEB_DIR . '/mu-plugins' );
$this->define( 'WPMU_PLUGIN_URL', env( 'WP_HOME' ) . '/mu-plugins' );
}

/**
* Create constants.
*
* @param null|mixed $value
*
* @return void
*/
public function define( string $const, $value = null ): void
{
if ( ! \defined( $const ) ) {
\define( $const, $value );
static::$list[ $const ] = $value;
}
}

/**
* Get list of defined constants.
*
* @return array constants in constants().
*/
public function get_defined(): array
{
return static::$list;
}
}
9 changes: 6 additions & 3 deletions src/ConfigTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ public static function define( string $name, $value ): void
public function required( string $name ): void
{
if ( ! \defined( $name ) ) {
// @phpstan-ignore-next-line.
// @phpstan-ignore-next-line.
$this->env->required( $name )->notEmpty();
}
}

/**
* @return null|string
*/
public static function get( string $name )
{
try {
Expand All @@ -55,7 +58,7 @@ public function apply(): void
*
* Debug must be on and 'development' set as WP_ENVIRONMENT_TYPE in the .env file.
*
* @return array|null list of constants defined.
* @return null|array list of constants defined.
*/
public function configMap(): ?array
{
Expand All @@ -73,7 +76,7 @@ public function configMap(): ?array
return ( new ReflectionClass( $configClass ) )->getStaticPropertyValue( 'configMap' );
}

return null;
return null;
}
/**
* Env defaults,.
Expand Down
10 changes: 5 additions & 5 deletions src/EnvConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getEnvironment(): string
*
* @param bool $enable
*
* @return self
* @return static
*/
public function symfony_debug( bool $enable = false ): ConfigInterface
{
Expand Down Expand Up @@ -124,9 +124,9 @@ abstract public function debug(): ConfigInterface;
abstract public function site_url(): ConfigInterface;

/**
* DB settings.
* DB settings.
*
* @return self
* @return static
*/
public function database(): ConfigInterface
{
Expand Down Expand Up @@ -171,7 +171,7 @@ abstract public function autosave(): ConfigInterface;
/**
* Authentication Unique Keys and Salts.
*
* @return self
* @return static
*/
public function salts(): ConfigInterface
{
Expand Down Expand Up @@ -215,6 +215,6 @@ protected function is_required(): void
} catch ( Exception $e ) {
var_dump( $e->getMessage() );
exit();
}//end try
}// end try
}
}
26 changes: 13 additions & 13 deletions src/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ class Setup extends EnvConfig
*/
public function __construct( string $path )
{
parent::__construct( $path );
parent::__construct( $path );
}

/**
* Singleton.
*
* @param $path
*
* @return object
*/
public static function init( $path ): ConfigInterface
public static function init( string $path ): ConfigInterface
{
if ( ! isset( self::$instance ) ) {
self::$instance = new self( $path );
Expand All @@ -36,10 +34,12 @@ public static function init( $path ): ConfigInterface
}

/**
* Runs config setup with default setting.
* Runs config setup with default setting.
*
* @param null|array $environment .
* @param bool $setup .
*
* @return null|static
*/
public function config( $environment = null, $setup = true )
{
Expand Down Expand Up @@ -89,7 +89,7 @@ public function config( $environment = null, $setup = true )
/**
* Setting the environment type.
*
* @return ConfigInterface
* @return static
*/
public function environment(): ConfigInterface
{
Expand All @@ -107,7 +107,7 @@ public function environment(): ConfigInterface
/**
* Debug Settings.
*
* @return Setup
* @return static
*/
public function debug(): ConfigInterface
{
Expand Down Expand Up @@ -135,15 +135,15 @@ public function debug(): ConfigInterface
break;
default:
Environment::production();
}//end switch
}// end switch

return $this;
}

/**
* Site Url Settings.
*
* @return self
* @return static
*/
public function site_url(): ConfigInterface
{
Expand All @@ -156,7 +156,7 @@ public function site_url(): ConfigInterface
/**
* Optimize.
*
* @return self
* @return static
*/
public function optimize(): ConfigInterface
{
Expand All @@ -168,7 +168,7 @@ public function optimize(): ConfigInterface
/**
* Memory Settings.
*
* @return self
* @return static
*/
public function memory(): ConfigInterface
{
Expand All @@ -181,7 +181,7 @@ public function memory(): ConfigInterface
/**
* SSL.
*
* @return self
* @return static
*/
public function force_ssl(): ConfigInterface
{
Expand All @@ -194,7 +194,7 @@ public function force_ssl(): ConfigInterface
/**
* AUTOSAVE and REVISIONS.
*
* @return self
* @return static
*/
public function autosave(): ConfigInterface
{
Expand Down
Loading

0 comments on commit 05a0a97

Please sign in to comment.