Skip to content

Commit

Permalink
Closes #5248
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 25, 2024
1 parent 1bc5624 commit b794fbc
Show file tree
Hide file tree
Showing 12 changed files with 0 additions and 611 deletions.
3 changes: 0 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
"optimize-autoloader": true,
"sort-packages": true
},
"suggest": {
"ext-soap": "To be able to generate mocks based on WSDL files"
},
"bin": [
"phpunit"
],
Expand Down

This file was deleted.

108 changes: 0 additions & 108 deletions src/Framework/MockObject/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
namespace PHPUnit\Framework\MockObject\Generator;

use const PHP_EOL;
use const PREG_OFFSET_CAPTURE;
use const WSDL_CACHE_NONE;
use function array_merge;
use function array_pop;
use function array_unique;
use function assert;
use function class_exists;
use function count;
use function explode;
use function extension_loaded;
use function implode;
use function in_array;
use function interface_exists;
Expand All @@ -29,15 +26,9 @@
use function method_exists;
use function mt_rand;
use function preg_match;
use function preg_match_all;
use function range;
use function serialize;
use function sort;
use function sprintf;
use function str_contains;
use function str_replace;
use function strlen;
use function strpos;
use function substr;
use function trait_exists;
use Exception;
Expand All @@ -61,8 +52,6 @@
use PHPUnit\Framework\MockObject\StubInternal;
use ReflectionClass;
use ReflectionMethod;
use SoapClient;
use SoapFault;
use Throwable;
use Traversable;

Expand Down Expand Up @@ -433,103 +422,6 @@ public function generate(string $type, bool $mockObject, bool $markAsMockObject,
return self::$cache[$key];
}

/**
* @throws RuntimeException
* @throws SoapExtensionNotAvailableException
*
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/5242
*/
public function generateClassFromWsdl(string $wsdlFile, string $className, array $methods = [], array $options = []): string
{
if (!extension_loaded('soap')) {
throw new SoapExtensionNotAvailableException;
}

$options['cache_wsdl'] = WSDL_CACHE_NONE;

try {
$client = new SoapClient($wsdlFile, $options);
$_methods = array_unique($client->__getFunctions());

unset($client);
} catch (SoapFault $e) {
throw new RuntimeException(
$e->getMessage(),
$e->getCode(),
$e,
);
}

sort($_methods);

$methodTemplate = $this->loadTemplate('wsdl_method.tpl');
$methodsBuffer = '';

foreach ($_methods as $method) {
preg_match_all('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\(/', $method, $matches, PREG_OFFSET_CAPTURE);

$lastFunction = array_pop($matches[0]);
$nameStart = $lastFunction[1];
$nameEnd = $nameStart + strlen($lastFunction[0]) - 1;
$name = str_replace('(', '', $lastFunction[0]);

if (empty($methods) || in_array($name, $methods, true)) {
$arguments = explode(
',',
str_replace(')', '', substr($method, $nameEnd + 1)),
);

foreach (range(0, count($arguments) - 1) as $i) {
$parameterStart = strpos($arguments[$i], '$');

if (!$parameterStart) {
continue;
}

$arguments[$i] = substr($arguments[$i], $parameterStart);
}

$methodTemplate->setVar(
[
'method_name' => $name,
'arguments' => implode(', ', $arguments),
],
);

$methodsBuffer .= $methodTemplate->render();
}
}

$optionsBuffer = '[';

foreach ($options as $key => $value) {
$optionsBuffer .= $key . ' => ' . $value;
}

$optionsBuffer .= ']';

$classTemplate = $this->loadTemplate('wsdl_class.tpl');
$namespace = '';

if (str_contains($className, '\\')) {
$parts = explode('\\', $className);
$className = array_pop($parts);
$namespace = 'namespace ' . implode('\\', $parts) . ';' . "\n\n";
}

$classTemplate->setVar(
[
'namespace' => $namespace,
'class_name' => $className,
'wsdl' => $wsdlFile,
'options' => $optionsBuffer,
'methods' => $methodsBuffer,
],
);

return $classTemplate->render();
}

/**
* @throws ReflectionException
*
Expand Down
9 changes: 0 additions & 9 deletions src/Framework/MockObject/Generator/templates/wsdl_class.tpl

This file was deleted.

64 changes: 0 additions & 64 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
use const LC_MONETARY;
use const LC_NUMERIC;
use const LC_TIME;
use const PATHINFO_FILENAME;
use const PHP_EOL;
use const PHP_URL_PATH;
use function array_keys;
use function array_merge;
use function array_reverse;
use function array_values;
use function assert;
use function basename;
use function chdir;
use function class_exists;
use function clearstatcache;
Expand All @@ -47,10 +44,7 @@
use function ob_get_contents;
use function ob_get_level;
use function ob_start;
use function parse_url;
use function pathinfo;
use function preg_match;
use function preg_replace;
use function restore_error_handler;
use function restore_exception_handler;
use function set_error_handler;
Expand Down Expand Up @@ -1421,64 +1415,6 @@ final protected function createTestProxy(string $originalClassName, array $const
return $testProxy;
}

/**
* Creates a mock object based on the given WSDL file.
*
* @throws MockObjectException
*
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/5242
*/
final protected function getMockFromWsdl(string $wsdlFile, string $originalClassName = '', string $mockClassName = '', array $methods = [], bool $callOriginalConstructor = true, array $options = []): MockObject
{
Event\Facade::emitter()->testTriggeredPhpunitDeprecation(
$this->valueObjectForEvents(),
'getMockFromWsdl() is deprecated and will be removed in PHPUnit 12 without replacement.',
);

if ($originalClassName === '') {
$fileName = pathinfo(basename(parse_url($wsdlFile, PHP_URL_PATH)), PATHINFO_FILENAME);
$originalClassName = preg_replace('/\W/', '', $fileName);
}

if (!class_exists($originalClassName)) {
eval(
(new MockGenerator)->generateClassFromWsdl(
$wsdlFile,
$originalClassName,
$methods,
$options,
)
);
}

$mockObject = (new MockGenerator)->testDouble(
$originalClassName,
true,
true,
$methods,
['', $options],
$mockClassName,
$callOriginalConstructor,
false,
false,
);

Event\Facade::emitter()->testCreatedMockObjectFromWsdl(
$wsdlFile,
$originalClassName,
$mockClassName,
$methods,
$callOriginalConstructor,
$options,
);

assert($mockObject instanceof MockObject);

$this->registerMockObject($mockObject);

return $mockObject;
}

protected function transformException(Throwable $t): Throwable
{
return $t;
Expand Down
33 changes: 0 additions & 33 deletions tests/_files/3530.wsdl

This file was deleted.

Loading

0 comments on commit b794fbc

Please sign in to comment.