-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jbcr/main
Fix Lambdatest error and add CS Fix
- Loading branch information
Showing
5 changed files
with
95 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
return PhpCsFixer\Config::create() | ||
->setRules([ | ||
'@Symfony' => true, | ||
'@Symfony:risky' => true, | ||
'@PSR2' => true, | ||
'array_syntax' => [ | ||
'syntax' => 'short' | ||
], | ||
'combine_consecutive_unsets' => true, | ||
'native_function_invocation' => [ | ||
'include' => [ | ||
'@compiler_optimized' | ||
] | ||
], | ||
'no_extra_blank_lines' => [ | ||
'break', | ||
'continue', | ||
'extra', | ||
'return', | ||
'throw', | ||
'use', | ||
'parenthesis_brace_block', | ||
'square_brace_block', | ||
'curly_brace_block', | ||
], | ||
'yoda_style' => [ | ||
'always_move_variable' => false, | ||
'equal' => false, | ||
'identical' => false, | ||
'less_and_greater' => false, | ||
], | ||
'ordered_class_elements' => true, | ||
'ordered_imports' => true, | ||
]) | ||
->setRiskyAllowed(true) | ||
->setFinder( | ||
PhpCsFixer\Finder::create() | ||
->in('src') | ||
->files()->name('*.php') | ||
) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,13 @@ | |
|
||
namespace Macintoshplus\Lambdatest\Driver; | ||
|
||
use Behat\MinkExtension\ServiceContainer\Driver\Selenium2Factory; | ||
use Macintoshplus\Lambdatest\Exception\LambdatestServiceException; | ||
use Macintoshplus\Lambdatest\Exception\TooManyParallelExecutionException; | ||
use SilverStripe\MinkFacebookWebDriver\FacebookFactory; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use WebDriver\Service\CurlService; | ||
|
||
final class LambdatestFactory extends Selenium2Factory | ||
final class LambdatestFactory extends FacebookFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
|
@@ -34,29 +37,31 @@ public function buildDriver(array $config) | |
{ | ||
$envValues = getenv(); | ||
if ((!isset($config['user']) || !isset($config['key'])) && (!isset($envValues['LT_USERNAME']) || !isset($envValues['LT_USERKEY']))) { | ||
throw new \Exception('Configure environment variable LT_USERNAME and LT_USERKEY with credential from Lambdatest'); | ||
throw new LambdatestServiceException('Configure environment variable LT_USERNAME and LT_USERKEY with credential from Lambdatest'); | ||
} | ||
|
||
$user = urlencode($envValues['LT_USERNAME'] ?? $config['user'] ?? null); | ||
$key = urlencode($envValues['LT_USERKEY'] ?? $config['key'] ?? null); | ||
|
||
$wd_host = $config['wd_host']; | ||
$config['capabilities']['extra_capabilities']['user'] = $user; | ||
$config['capabilities']['extra_capabilities']['accessKey'] = $key; | ||
|
||
$infos = parse_url($wd_host); | ||
$curl = new CurlService(); | ||
$url = sprintf('https://%s:%[email protected]/automation/api/v1/org/concurrency', $user, $key); | ||
list($result, $infos) = $curl->execute('GET', $url); | ||
|
||
$wd_host = sprintf( | ||
'%s://%s:%s@%s%s%s%s%s', | ||
$infos['scheme'], | ||
$user, | ||
$key, | ||
$infos['host'], | ||
isset($infos['port']) ? ':'.$infos['port'] : '', | ||
$infos['path'] ?? '', | ||
isset($infos['query']) ? '?'.$infos['query'] : '', | ||
isset($infos['fragment']) ? '#'.$infos['fragment'] : '' | ||
); | ||
//Example : {"data":{"created":0,"max_concurrency":1,"max_queue":150,"pqueued":0,"queued":0,"running":0},"status":"success"} | ||
$data = json_decode($result, true); | ||
if (json_last_error() !== \JSON_ERROR_NONE) { | ||
throw new LambdatestServiceException('JSON Error on decode Lambdatest response : '.json_last_error().' '.json_last_error_msg()); | ||
} | ||
if (isset($data['data']) === false || isset($data['data']['max_concurrency']) === false || isset($data['data']['running']) === false) { | ||
throw new LambdatestServiceException('Concurency response is a valid JSON but does not contrains expected keys'); | ||
} | ||
|
||
$config['wd_host'] = $wd_host; | ||
if ((int) ($data['data']['max_concurrency']) <= (int) ($data['data']['running'])) { | ||
throw new TooManyParallelExecutionException(sprintf('Unable to launch anothe parallel automation test. max concurency: %s, current running test: %s', $data['data']['max_concurrency'], $data['data']['running'])); | ||
} | ||
|
||
return parent::buildDriver($config); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Macintoshplus\Lambdatest\Exception; | ||
|
||
class LambdatestServiceException extends \Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Macintoshplus\Lambdatest\Exception; | ||
|
||
final class TooManyParallelExecutionException extends LambdatestServiceException | ||
{ | ||
} |