Skip to content

Commit

Permalink
Merge branch 'release/1.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelcom committed Sep 11, 2015
2 parents c99eb9a + 4d011fd commit 7398544
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

# 1.1.2
- issue #34 - Name "0001CreateRequest" is invalid, please provide a valid name
- issue #33 - Name "" is invalid, please provide a valid name (operation named 0001CreateRequest)

## 1.1.1
- Improve readme file, Wiki has been created and filled up with useful additional informations into the FAQ page.

Expand Down
1 change: 1 addition & 0 deletions src/Generator/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static function getPart($optionValue, $string)
{
$elementType = '';
$string = str_replace('_', '', $string);
$string = preg_replace('/([0-9])/', '', $string);
if (!empty($string)) {
switch ($optionValue) {
case GeneratorOptions::VALUE_END:
Expand Down
11 changes: 10 additions & 1 deletion src/Model/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,19 @@ public function __construct(Generator $generator, $name, $parameterType, $return
->setIsUnique($isUnique)
->setOwner($service);
}
/**
* Method name can't starts with numbers
* @see \WsdlToPhp\PackageGenerator\Model\AbstractModel::getCleanName()
* @return string
*/
public function getCleanName($keepMultipleUnderscores = true)
{
return preg_replace('/^(\d+)([a-zA-Z0-9]*)$/', '_$2', parent::getCleanName($keepMultipleUnderscores));
}
/**
* Returns the name of the method that is used to call the operation
* It takes care of the fact that the method might not be the only one named as it is.
* @uses AbstractModel::getCleanName()
* @uses Method::getCleanName()
* @uses AbstractModel::replaceReservedPhpKeyword()
* @uses AbstractModel::getOwner()
* @uses AbstractModel::getPackagedName()
Expand Down
39 changes: 38 additions & 1 deletion tests/Generator/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,20 @@ public function testGetValueWithinItsType()
/**
*
*/
public function testCleanString()
public function testGetPartStart()
{
$this->assertSame('events', Utils::getPart(GeneratorOptions::VALUE_START, 'eventsGet'));
$this->assertSame('events', Utils::getPart(GeneratorOptions::VALUE_START, '_events'));
}
/**
*
*/
public function testGetPartEnd()
{
$this->assertSame('Get', Utils::getPart(GeneratorOptions::VALUE_END, 'eventsGet'));
$this->assertSame('Partition', Utils::getPart(GeneratorOptions::VALUE_END, 'eventsGetPartition'));
$this->assertSame('events', Utils::getPart(GeneratorOptions::VALUE_END, '_events'));
}
/**
*
*/
Expand Down Expand Up @@ -95,4 +104,32 @@ public function testGetContentFromUrlContextOptionsBasicAuthProxy()
),
), Utils::getContentFromUrlContextOptions('http://www.foo.com', 'foo', 'bar', 'dns.proxy.com', 4545, 'foo', 'bar'));
}
/**
*
*/
public function testGetPartStringBeginingWithInt()
{
$this->assertSame('My', Utils::getPart(GeneratorOptions::VALUE_START, '0MyOperation'));
}
/**
*
*/
public function testGetPartStringBeginingWithMultipleInt()
{
$this->assertSame('My', Utils::getPart(GeneratorOptions::VALUE_START, '0123456789MyOperation'));
}
/**
*
*/
public function testGetEndPartStringBeginingWithMultipleInt()
{
$this->assertSame('Operation', Utils::getPart(GeneratorOptions::VALUE_END, '012345678MyOperation'));
}
/**
*
*/
public function testGetEndPartStringEndingWithInt()
{
$this->assertSame('Operation', Utils::getPart(GeneratorOptions::VALUE_END, 'MyOperation0'));
}
}
44 changes: 44 additions & 0 deletions tests/Model/MethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,48 @@ public function testMultipleServicesSameMethodsWithoutPurging()
$this->assertSame('login_1', $service2->getMethod('login')->getMethodName());
$this->assertSame('Login', $service3->getMethod('Login')->getMethodName());
}
/**
*
*/
public function testGetCleanNameWithOneInt()
{
Service::purgeUniqueNames();
$service1 = new Service(self::getBingGeneratorInstance(), 'Login');
$service1->addMethod('0MyOperation', 'int', 'id');

$this->assertSame('_MyOperation', $service1->getMethod('0MyOperation')->getCleanName());
}
/**
*
*/
public function testGetCleanNameWithMultipleInt()
{
Service::purgeUniqueNames();
$service1 = new Service(self::getBingGeneratorInstance(), 'Login');
$service1->addMethod('0123456789MyOperation', 'int', 'id');

$this->assertSame('_MyOperation', $service1->getMethod('0123456789MyOperation')->getCleanName());
}
/**
*
*/
public function testNameIsCleanWithOneInt()
{
Service::purgeUniqueNames();
$service1 = new Service(self::getBingGeneratorInstance(), 'Login');
$service1->addMethod('0MyOperation', 'int', 'id');

$this->assertFalse($service1->getMethod('0MyOperation')->nameIsClean());
}
/**
*
*/
public function testNameIsCleanWithMultipleInt()
{
Service::purgeUniqueNames();
$service1 = new Service(self::getBingGeneratorInstance(), 'Login');
$service1->addMethod('0123456789MyOperation', 'int', 'id');

$this->assertFalse($service1->getMethod('0123456789MyOperation')->nameIsClean());
}
}

0 comments on commit 7398544

Please sign in to comment.