static $_all_classes = '_ALL_CLASSES'; static function register_double($double, $of, $isDoubleOfInterface = false) { $_all_classes = self::$_all_classes; global ${$_all_classes}; if (${$_all_classes} && is_array(${$_all_classes}) && !isset(${$_all_classes}['exists'][$double])) { // Mark as exists ${$_all_classes}['exists'][$double] = $double; if ($isDoubleOfInterface) { // If we're doubling an interface, mark the double as an implementor if (!isset(${$_all_classes}['implementors'][$of])) { ${$_all_classes}['implementors'][$of] = array(); } ${$_all_classes}['implementors'][$of][$double] = $double; // And don't have any parents ${$_all_classes}['parents'][$double] = array(); } else { // Otherwise parents are same as good twin's parents + good twin itself ${$_all_classes}['parents'][$double] = array_merge(${$_all_classes}['parents'][$of], array($of => $of)); // And see if good twin is marked as implementor of any interfaces - we should be too foreach (${$_all_classes}['implementors'] as $interface => $implementors) { if (array_key_exists($of, $implementors)) { ${$_all_classes}['implementors'][$interface][$double] = $double; } } } } } } Phockito::$type_registrar = 'Phockito::SilverStripe';
function tearDown() { PhockitoSilverStripe::$_all_classes = self::$orig_all_classes; Phockito::$type_registrar = self::$orig_type_registrar; }
} } // Register in implementors foreach ($this->implementors as $interface => $implementors) { $lImplementors = array_map('strtolower', $implementors); if (in_array($lDoubled, $lImplementors)) { $this->implementors[$interface][] = $double; } } } } /** * The callback that Phockito will call every time there's a new double created * * @param string $double - The class name of the new double * @param string $of - The class new of the doubled class or interface * @param bool $isDoubleOfInterface - True if $of is an interface, False if it's a class */ static function register_double($double, $of, $isDoubleOfInterface = false) { $manifest = SS_ClassLoader::instance()->getManifest(); if (!$manifest instanceof PhockitoClassManifestUpdater) { $manifest = new PhockitoClassManifestUpdater($manifest); SS_ClassLoader::instance()->pushManifest($manifest, true); } $manifest->addDouble($double, $of, $isDoubleOfInterface); } } require_once BASE_PATH . '/vendor/hafriedlander/phockito/Phockito.php'; Phockito::$type_registrar = 'PhockitoClassManifestUpdater';
static function register_double($double, $of, $isDoubleOfInterface = false) { $_all_classes = self::$_all_classes; global ${$_all_classes}; if (${$_all_classes} && is_array(${$_all_classes}) && !isset(${$_all_classes}['exists'][$double])) { // Mark as exists ${$_all_classes}['exists'][$double] = $double; if ($isDoubleOfInterface) { // If we're doubling an interface, mark the double as an implementor if (!isset(${$_all_classes}['implementors'][$of])) { ${$_all_classes}['implementors'][$of] = array(); } ${$_all_classes}['implementors'][$of][$double] = $double; // And don't have any parents ${$_all_classes}['parents'][$double] = array(); } else { // Otherwise parents are same as good twin's parents + good twin itself ${$_all_classes}['parents'][$double] = array_merge(${$_all_classes}['parents'][$of], array($of => $of)); // And see if good twin is marked as implementor of any interfaces - we should be too foreach (${$_all_classes}['implementors'] as $interface => $implementors) { if (array_key_exists($of, $implementors)) { ${$_all_classes}['implementors'][$interface][$double] = $double; } } } } } } require_once BASE_PATH . '/vendor/hafriedlander/phockito/Phockito.php'; Phockito::$type_registrar = 'PhockitoClassGlobalUpdater';