I try to create my own library, with it's own namespace so it can be included in other projects.
I have done that and composer install runs without errors, but when I try to run my unit tests in my library it doesn't find any classes neither for mocking or for direct initialisation.
My folder structure is like this:
ProjectFolder
|
\_src
| \_Sap
| \_Classes
|
\_tests
| \_Sap
| \_TestClasses
| bootstrap.php
\_vendor
The namespace used in classes follows this pattern:
namespace PuC\Sap;
The one used in the tests has this pattern:
namespace PuC\Sap\Tests\Sap;
My composer.json looks like this:
"autoload": {
"psr-4": {
"PuC\\Sap\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"PuC\\Sap\\Tests\\": "tests/"
}
},
In my tests folder I have added a bootstrap.php and refer to it in my phpunit.xml file:
<?php
$loader = #include __DIR__ . '/../vendor/autoload.php')
$loader->add('Sap', __DIR__);
No when I run this in the bash I get:
$ bin/phpunit tests/
PHPUnit 8.4.3 by Sebastian Bergmann and contributors.
......
7) PuC\Sap\Tests\Sap\HouseSoapServiceTest::testGetHouseData
Cannot stub or mock class or interface "PuC\Sap\Client\SapSoapClient" which does not exist
Same problem when I try to initialise the class directly.
Are my paths wrong? My namespaces?
The problem was the additional folder in my src folder. With this modified structure the tests are passing and the classes are found:
ProjectFolder
|
\_src
| \_Classes
|
\_tests
| \_Sap
| \_TestClasses
| bootstrap.php
\_vendor
Thanks to Robbie Averill for pointing me in the right direction.
Related
I am currently using terraform to provision Infrastructure in the cloud. On Top of Terraform I run GitHub Actions to automate even more Steps.
In this case, after provisioning the infrastructure I generate an inventory file (for ansible) with a bash script using the generated cluster.tfstate to parse names and ips.
However the Script cant run, as it throws following error
Run bash ./generate-inventory.sh cluster.tfstate > ../hosts.ini
parse error: Invalid numeric literal at line 1, column 9
Error: Process completed with exit code 4.
Running it locally however works. When i do a cat on the cluster.tfstate inside the workflow the following is the case
Run cat cluster.tfstate
***
"version": 4,
"terraform_version": "1.0.1",
"serial": 386,
"lineage": "3d16a659-b093-551c-b3ab-a1cf8aa5031c",
"outputs": ***
"master_ip_addresses": ***
"value": ***
Does GitHub Actions modify the json that is evaluated by my script because of Secrets i have created? Or are the stars only in the output in the shell?
The Code of the workflow can be seen here https://github.com/eco-bench/eco-bench/blob/main/.github/workflows/terraform.yml
Thanks!
Following did the trick
source "local_file" "AnsibleInventory" {
content = templatefile("inventory.tmpl",
{
worker = {
for key, instance in google_compute_instance.worker :
instance.name => instance.network_interface.0.access_config.0.nat_ip
}
master = {
for key, instance in google_compute_instance.master :
instance.name => instance.network_interface.0.access_config.0.nat_ip
}
}
)
filename = "./inventory.ini"
}
The Template looks like this
[all:vars]
ansible_connection=ssh
ansible_user=lucas
[cloud]
%{ for ip in master ~}
${name} ${ip}
%{ endfor ~}
[edge]
%{ for ip in worker ~}
${ip}
%{ endfor ~}
[cloud:vars]
kubernetes_role=master
[edge:vars]
kubernetes_role=edge
I would like to append an element to an existing JSON file where I have the working directory as the key and the working directory + the contents as the value in a string array format.
Lets say I have the following structure:
Docs (Directory)
|
+-- RandomFile.json
|
+-- Readme (Working Directory)
| |
| +-- Readme.md
| +-- Readyou.md
What I would like to achieve is the structure below with the working directory as the prefix for every element in the array.
"Readme": ["Readme/Readme.md", "Readme/Readyou.md"]
From the output above, I would like to append that to the contents of the RandomFile.json which currently looks like this:
{
"docs": {
"Doc": ["doc1"]
}
}
to this:
{
"docs": {
"Doc": ["doc1"],
"Readme": ["Readme/Readme.md", "Readme/Readyou.md"]
}
}
Is it something that can be managed straightforward using bash and jq?
This requires jq 1.6 in order to use the --args option.
$ jq --arg wd "$(basename "$PWD")" '.docs+={($wd): $ARGS.positional | map("\($wd)/\(.)")}' ../RandomFile.json --args *
{
"docs": {
"Doc": [
"doc1"
],
"Readme": [
"Readme/Readme.md",
"Readme/Readyou.md"
]
}
}
The shell is used to pass the base name of the current working directory as the variable $wd.
The shell is also used to pass the names of all the files in the current working directory as separate arguments.
The file to edit is assumed to be ../RandomFile.json; if you only know that there is a JSON file in the parent, you can use ../*.json instead.
Use += to update the .docs object of the original with a new key (the working directory) and list of file names. map prefixes each element of $ARGS.positional with $wd.
How can I find all files ending in .csv in a given directory using Pharo?
This will work too:
'G:\My Drive\Data Mining' asFileReference allChildrenMatching: '*.csv'
Use basename and endsWith: for the children of the directory (FileReference). From http://pharobooks.gforge.inria.fr/PharoByExampleTwo-Eng/latest/FileSystem.pdf:
working := 'G:\My Drive\Data Mining' asFileReference.
working allChildren select: [ :each | each basename endsWith: '.csv' ]
I've tried to get linux list of my all files and directories in specified path to json format using ls and jq.
Desired output:
this is all what I have...
ls | jq -R '[.]' | jq -s -c 'add'
Is it possible to build output like above in the picture?
The following only handles vanilla files and is neither portable nor robust but should be sufficient to get you on your way.
The JSON structure that is emitted is very similar to the output of the tree program (shown below); in particular, it uses directory components as strings, since that produces an economical
hierarchy allowing queries such as .a.b to view details about the directory ‘./a/b’. To provide jq the necessary data, we use find . -ls.
jqtree
#!/bin/bash
find . -ls | jq -nR '
# Return an object with useful information
def gather:
[splits(" +")] as $in
| { pathname: $in[-1], entrytype: $in[2][0:1], size: ($in[6] | tonumber) };
reduce (inputs | gather) as $entry ({};
($entry.pathname | split("/") ) as $names
| if ($entry|.entrytype == "-") then
($names[0:-1] + ["items"]) as $p
| setpath($p; getpath($p) + [{name: $names[-1], size: $entry.size}])
else . end) '
Demo
$ tree
.
|-- a
| `-- b
| `-- foo
|-- big
|-- foo
`-- so
$ ~/bin/jqtree
{
".": {
"items": [
{
"name": "big",
"size": 1025
},
{
"name": "so",
"size": 667
},
{
"name": "foo",
"size": 0
}
],
"a": {
"b": {
"items": [
{
"name": "foo",
"size": 0
}
]
}
}
}
}
This Linux works on mips. Not have find . -ls (PARAM not available), tree not have.
Maybe someone can compile tree package.
BusyBox v1.22.1 (2017-06-29 11:15:20 CST) multi-call binary.
Usage: find [-HL] [PATH]... [OPTIONS] [ACTIONS]
Search for files and perform actions on them.
First failed action stops processing of current file.
Defaults: PATH is current directory, action is '-print'
-L,-follow Follow symlinks
-H ...on command line only
Actions:
ACT1 [-a] ACT2 If ACT1 fails, stop, else do ACT2
ACT1 -o ACT2 If ACT1 succeeds, stop, else do ACT2
Note: -a has higher priority than -o
-name PATTERN Match file name (w/o directory name) to PATTERN
-iname PATTERN Case insensitive -name
If none of the following actions is specified, -print is assumed
-print Print file name
I can't seem to use JSON::XS's OO interface properly. The following croaks with an error I can't track down:
use JSON::XS;
my $array = ['foo', 'bar'];
my $coder = JSON::XS->new->utf8->pretty;
print $coder->encode_json($array);
This croaks with the following: Usage: JSON::XS::encode_json(scalar) at test.pl line 5. I have been combing through the code for JSON::XS and I can't find a "Usage:" warning anywhere. My usage seems to be pretty well matched with the examples in the documentation. Can anyone tell me where I have gone wrong?
JSON::XS has two interfaces: functional and OO.
In the functional interface, the function name is encode_json.
In the OO interface, the method is simply encode, not encode_json.
Both of the following two snippets work:
# Functional | # OO
------------------------------+-----------------------------------------
|
use JSON::XS; | use JSON::XS;
my $array = ['foo', 'bar']; | my $array = [ 'foo', 'bar' ];
|
print encode_json($array); | my $coder = JSON::XS->new->utf8->pretty;
| print $coder->encode($array);
|
# ["foo","bar"] | # [
| # "foo",
| # "bar"
| # ]