Skip to content

Commit b94b44c

Browse files
implementa metodologia de retorno de dados fake fixo
1 parent 5c21e17 commit b94b44c

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"codset":"558","tipset":"Unidade","nomabvset":"FFLCH","nomset":"Diretoria Faculdade de Filosofia, Letras e Ci\u00eancias Humanas","codsetspe":"0"},{"codset":"559","tipset":"Divis\u00e3o","nomabvset":"DVACAD-08","nomset":"Divis\u00e3o Acad\u00eamica","codsetspe":"558"}]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"codund":"8","tipund":"Ensino e Pesquisa","codcam":"10","numpro":"123","sglund":"FFLCH","nomund":"Faculdade de Filosofia, Letras e Ci\u00eancias Humanas","nomabvund":"Fac de Fil Let e Ci\u00eanc Humanas","staareexa":"N","staarehum":"S","staarebio":"N","dtaatvund":"1934-01-25 00:00:00","dtadtvund":"","staundvin":"N","sglusp":"USP","dtacriund":"1934-01-25 00:00:00","timestamp":"\u0003G\u000e\u00e4","dtainival":"1934-01-25 00:00:00","codpubadm":"","codema":"fflch@usp.br","numpticam":"1","artttm":"a","nomundigl":"College of Philosophy, Literature and Human Sciences","nomundepa":"","nomundfcs":"","nomabvundigl":"Philosophy, Literature & Human Sciences","nomabvundepa":"","nomabvundfcs":"","codundfis":"1","numseqendusp":"1","codloc":"1","epflgr":"Rua do Lago","idfcxaptl":"","codendptl":"05508900","nombro":"Butant\u00e3","nomedf":"Administra\u00e7\u00e3o","starefund":"S","starefundfis":"S","numlgr":"717","cpllgr":"","dtacad":"","codpescad":"","dtaultalt":"","codpesalt":"","dtadtv":"","stapddtci":"","sglest":"SP","codpas":"1","cidloc":"S\u00e3o Paulo","codddd":"11","cidlocfon":"SAM PAOLO","cidlocnor":"SAOPAULO","stacapest":"S","stacappas":""}

src/Estrutura.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Uspdev\Replicado;
44

5+
use Uspdev\Replicado\Replicado as Config;
6+
57
class Estrutura
68
{
79
/**
@@ -34,6 +36,8 @@ public static function dump($codset)
3436
*/
3537
public static function listarSetores($codund = null)
3638
{
39+
if(Config::getConfig('fake')) return Config::getFake('Estrutura.listarSetores');
40+
3741
$query = "SELECT codset, tipset, nomabvset, nomset, codsetspe FROM SETOR
3842
WHERE codund = convert(int,:codund) AND dtadtvset IS NULL AND nomset NOT LIKE 'Inativo'
3943
ORDER BY codset ASC";
@@ -105,6 +109,7 @@ public static function listarUnidades()
105109
*/
106110
public static function obterUnidade($codund)
107111
{
112+
if(Config::getConfig('fake')) return Config::getFake('Estrutura.obterUnidade');
108113
$query = DB::getQuery('Estrutura.obterUnidade.sql');
109114
$param = ['codund' => $codund];
110115
return DB::fetch($query, $param);

src/Replicado.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Monolog\Handler\StreamHandler;
66
use Monolog\Logger;
77
use Uspdev\Cache\Cache;
8+
use SplFileInfo;
89

910
class Replicado
1011
{
@@ -35,12 +36,13 @@ class Replicado
3536
public $pathlog = '/tmp/replicado.log';
3637
public $debug = false;
3738
public $debugLevel = 1; // 1: somente erros, 2: log de queries
39+
public $fake = false;
3840

3941
/** Variaveis que podem ser atualizadas pelo setConfig() */
4042
protected $vars = [
4143
'host', 'port', 'database', 'username', 'password',
4244
'codundclg', 'codundclgs', 'sybase', 'usarCache', 'cacheExpiry', 'cacheSmall',
43-
'pathlog', 'debug', 'debugLevel'];
45+
'pathlog', 'debug', 'debugLevel', 'fake'];
4446

4547
private function __construct()
4648
{}
@@ -178,4 +180,22 @@ public function log(string $channelName, string $message, string $level = 'error
178180
SELF::$logger->$level($message);
179181
}
180182

183+
/**
184+
* Retorna a estrutura de dados fixa para finalidades de testes
185+
*
186+
*/
187+
public static function getFake($name)
188+
{
189+
$path = new SplFileInfo(__DIR__);
190+
$path = $path->getRealPath();
191+
$path .= DIRECTORY_SEPARATOR;
192+
$path .= '..';
193+
$path .= DIRECTORY_SEPARATOR;
194+
$path .= 'resources';
195+
$path .= DIRECTORY_SEPARATOR;
196+
$path .= 'fake';
197+
$json = file_get_contents($path . DIRECTORY_SEPARATOR . $name . '.json');
198+
199+
return json_decode($json, true);
200+
}
181201
}

0 commit comments

Comments
 (0)