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

Commit

Permalink
Adds before and after loading actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jedrzejchalubek committed Feb 12, 2017
1 parent 09946fb commit 41285f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/Gin/Foundation/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,26 @@ public function __construct($config)
* @return void
*/
public function register()
{
do_action('Tonik\Gin\Foundation\Autoloader\before_load');

$this->load();

do_action('Tonik\Gin\Foundation\Autoloader\after_load');
}

/**
* Localize and autoloads files.
*
* @return void
*/
public function load()
{
foreach ($this->config['autoload'] as $file) {
if ( ! locate_template($this->getRelativePath($file), true, true)) {
throw new FileNotFoundException("Autoloaded file [{$this->getPath($file)}] cannot be found. Please, check your autoloaded entries in `config/theme.php` file.");
}
}

return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/Gin/Foundation/AutoloaderTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Brain\Monkey\Functions;
use Brain\Monkey\WP\Actions;
use Tonik\Gin\Foundation\Autoloader;
use Tonik\Gin\Foundation\Config;
use Tonik\Gin\Foundation\Exception\FileNotFoundException;
Expand Down Expand Up @@ -79,6 +80,9 @@ public function it_should_return_true_on_successfully_autoloading()
$config = $this->getConfig();
$autoloader = $this->getAutoloader($config);

Actions::expectFired('Tonik\Gin\Foundation\Autoloader\before_load')->once();
Actions::expectFired('Tonik\Gin\Foundation\Autoloader\after_load')->once();

Functions::expect('locate_template')
->once()
->with('src/file/to/load.php', true, true)
Expand All @@ -96,7 +100,7 @@ public function it_should_return_true_on_successfully_autoloading()
->with('autoload')
->andReturn(['file/to/load.php']);

$this->assertEquals($autoloader->register(), true);
$autoloader->register();
}

public function getConfig()
Expand Down

0 comments on commit 41285f1

Please sign in to comment.