3 namespace RedUNIT\Blackhole;
5 use RedUNIT\Blackhole as Blackhole;
6 use RedBeanPHP\Facade as R;
7 use RedBeanPHP\Facade as Facade;
8 use RedBeanPHP\RedException as RedException;
13 * This test suite tests whether we can define dynamic
14 * plugins using the ext() method on the facade.
16 * @file RedUNIT/Blackhole/Plugins.php
17 * @desc Tests extending R facade dynamically.
18 * @author Gabor de Mooij and the RedBeanPHP Community
19 * @license New BSD/GPLv2
21 * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
22 * This source file is subject to the New BSD/GPLv2 License that is bundled
23 * with this source code in the file license.txt.
25 class Plugins extends Blackhole
28 * Test if we can dynamically extend the R-facade.
32 public function testDynamicPlugins()
34 testpack('Test dynamic plugins');
37 R::ext( 'makeTea', function() {
38 return 'sorry cant do that!';
41 asrt( R::makeTea(), 'sorry cant do that!' );
44 R::ext( 'multiply', function( $a, $b ) {
48 asrt( R::multiply( 3, 4 ), 12 );
50 //can we call R inside?
51 R::ext( 'singVersion', function() {
52 return R::getVersion() . ' lalala !';
55 asrt( R::singVersion(), ( R::getVersion().' lalala !' ) );
57 //should also work with Facade
58 asrt( Facade::singVersion(), ( R::getVersion().' lalala !' ) );
62 R::ext( '---', function() {} );
64 } catch ( RedException $e ) {
65 asrt( $e->getMessage(), 'Plugin name may only contain alphanumeric characters.' );
69 R::__callStatic( '---', function() {} );
71 } catch ( RedException $e ) {
72 asrt( $e->getMessage(), 'Plugin name may only contain alphanumeric characters.' );
78 } catch ( RedException $e ) {
79 asrt( $e->getMessage(), 'Plugin \'invalidMethod\' does not exist, add this plugin using: R::ext(\'invalidMethod\')' );