Skip to content

Commit

Permalink
Merge pull request #83 from timber/2040_remove_composer
Browse files Browse the repository at this point in the history
Remove Composer.json; install through Travis
  • Loading branch information
jarednova authored Jul 4, 2019
2 parents 3253ae2 + f1c3382 commit 5226755
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:

before_script:
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
- composer install --dev
- composer install

script:
- vendor/phpunit/phpunit/phpunit
18 changes: 5 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,19 @@
"type":"wordpress-theme",
"minimum-stability" : "stable",
"authors": [
{
"name": "jarednova",
"email": "[email protected]"
}
{
"email": "[email protected]",
"name": "jarednova"
}
],
"repositories": [
{
"type": "composer",
"url": "https://wpackagist.org"
}
],
"extra": {
"installer-paths": {
"../../plugins/{$name}/": [
"wpackagist-plugin/*",
"type:wordpress-plugin"
]
}
},
"require": {
"wpackagist-plugin/timber-library": "1.*"
"timber/timber": "1.*"
},
"require-dev": {
"phpunit/phpunit": "5.7.16|6.*"
Expand Down
17 changes: 16 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,30 @@
* @since Timber 0.1
*/

/**
* If you are installing Timber as a Composer dependency in your theme, you'll need this block
* to load your dependencies and initialize Timber. If you are using Timber via the WordPress.org
* plug-in, you can safely delete this block.
*/
$composer_autoload = __DIR__ . '/vendor/autoload.php';
if ( file_exists($composer_autoload) ) {
require_once( $composer_autoload );
$timber = new Timber\Timber();
}

/**
* This ensures that Timber is loaded and available as a PHP class.
* If not, it gives an error message to help direct developers on where to activate
*/
if ( ! class_exists( 'Timber' ) ) {

add_action( 'admin_notices', function() {
echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url( admin_url( 'plugins.php#timber' ) ) . '">' . esc_url( admin_url( 'plugins.php' ) ) . '</a></p></div>';
});

add_filter('template_include', function( $template ) {
return get_stylesheet_directory() . '/static/no-timber.html';
});

return;
}

Expand Down
5 changes: 0 additions & 5 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?php

if ( file_exists($composer_autoload = __DIR__ . '/../vendor/autoload.php') ) {
require_once($composer_autoload);
}


$_tests_dir = getenv('WP_TESTS_DIR');
if ( !$_tests_dir ) $_tests_dir = '/tmp/wordpress-tests-lib';

Expand Down
34 changes: 11 additions & 23 deletions tests/test-timber-starter-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ class TestTimberStarterTheme extends WP_UnitTestCase {

function setUp() {
self::_setupStarterTheme();
require_once(get_template_directory().'/functions.php');
switch_theme('starter-theme');
require_once(__DIR__.'/../functions.php');
}

function tearDown() {
switch_theme('twentythirteen');
}

function testTimberExists() {
$context = Timber::context();
$this->assertTrue(is_array($context));
}

function testFunctionsPHP() {
$context = Timber::context();
$this->assertEquals('StarterSite', get_class($context['site']));
Expand All @@ -25,30 +31,12 @@ function testLoading() {
}

static function _setupStarterTheme(){
$dest = WP_CONTENT_DIR.'/themes/starter-theme/';
$src = __DIR__.'/../../starter-theme/';
if (is_dir($src)) {
self::_copyDirectory($src, $dest);
switch_theme('starter-theme');
} else {
echo 'no its not';
$dest = WP_CONTENT_DIR.'/themes/starter-theme';
$src = realpath(__DIR__.'/../../starter-theme/');
if ( is_dir($src) && !file_exists($dest) ) {
symlink($src, $dest);
}
}

static function _copyDirectory($src, $dst){
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
self::_copyDirectory($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}

}

0 comments on commit 5226755

Please sign in to comment.