Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add trait for wiring test assertions

  • Loading branch information...
commit bf8c73ce384ee325623f0554fbcaecfa80860406 1 parent 29c646d
Paul M. Jones pmjones authored
1  src.php
@@ -14,6 +14,7 @@
14 14 require_once __DIR__ . '/src/Aura/Framework/Intl/TranslatorFactory.php';
15 15 require_once __DIR__ . '/src/Aura/Framework/Signal/Manager.php';
16 16 require_once __DIR__ . '/src/Aura/Framework/System.php';
  17 +require_once __DIR__ . '/src/Aura/Framework/Test/WiringAssertionsTrait.php';
17 18 require_once __DIR__ . '/src/Aura/Framework/View/Helper/Route.php';
18 19 require_once __DIR__ . '/src/Aura/Framework/Web/Controller/AbstractPage.php';
19 20 require_once __DIR__ . '/src/Aura/Framework/Web/Controller/Factory.php';
88 src/Aura/Framework/Test/WiringAssertionsTrait.php
... ... @@ -0,0 +1,88 @@
  1 +<?php
  2 +/**
  3 + *
  4 + * This file is part of the Aura project for PHP.
  5 + *
  6 + * @package Aura.Framework
  7 + *
  8 + * @license http://opensource.org/licenses/bsd-license.php BSD
  9 + *
  10 + */
  11 +namespace Aura\Framework\Test;
  12 +
  13 +/**
  14 + *
  15 + * A trait for assertions when testing config wiring. You should use
  16 + * this trait in a class that extends PHPUnit_Framework_TestCase, and you
  17 + * should call $this->loadDi() in your setup method.
  18 + *
  19 + * @package Aura.Framework
  20 + *
  21 + */
  22 +trait WiringAssertionsTrait
  23 +{
  24 + /**
  25 + *
  26 + * The DI container from the framework.
  27 + *
  28 + * @var Aura\Di\Container
  29 + *
  30 + */
  31 + protected $di;
  32 +
  33 + /**
  34 + *
  35 + * Loads the $di property from the global variable $AURA_FRAMEWORK_DI.
  36 + *
  37 + * @return void
  38 + *
  39 + */
  40 + protected function loadDi()
  41 + {
  42 + $this->di = $GLOBALS['AURA_FRAMEWORK_DI'];
  43 + }
  44 +
  45 + /**
  46 + *
  47 + * Asserts that a DI service is an instance of a particular class. This
  48 + * tests that the service is instantiated without wiring errors; whether
  49 + * or not the wiring is sane is something else entirely.
  50 + *
  51 + * @param string $service The service name.
  52 + *
  53 + * @param string $class The class name.
  54 + *
  55 + * @return void
  56 + *
  57 + */
  58 + protected function assertGet($service, $class)
  59 + {
  60 + $object = $this->di->get($service);
  61 + $this->assertInstanceOf($class, $object);
  62 + return $object;
  63 + }
  64 +
  65 + /**
  66 + *
  67 + * Asserts that a new instance is of a particular class. This tests that
  68 + * the class is instantiated without wiring errors; whether or not the
  69 + * wiring is sane is something else entirely.
  70 + *
  71 + * @param string $expect Should be an instance of this class.
  72 + *
  73 + * @param string $actual An alternative class to instantiate; useful for
  74 + * mocks of abstract expected classes.
  75 + *
  76 + * @return void
  77 + *
  78 + */
  79 + protected function assertNewInstance($expect, $actual = null)
  80 + {
  81 + if (! $actual) {
  82 + $actual = $expect;
  83 + }
  84 + $object = $this->di->newInstance($actual);
  85 + $this->assertInstanceOf($expect, $object);
  86 + return $object;
  87 + }
  88 +}

0 comments on commit bf8c73c

Please sign in to comment.
Something went wrong with that request. Please try again.