What means the following PHP Syntax: `$this->{$this->name}`? - phpunit

I am new to Magento 2. I am testing a class with PhpUnit.
When I run the test I obtain this error:
ArgumentCountError : Too few arguments to function Magenio\Todo\Test\Unit\Service\TaskRepositoryTest::testGetList(), 0 passed in /opt/project/vendor/phpunit/phpunit/src/Framework/TestCase.php on line 1414 and exactly 1 expected
I checked the TestCase.php file and the line 1414 and related lines are those:
protected function runTest()
{
if (\trim($this->name) === '') {
throw new Exception(
'PHPUnit\Framework\TestCase::$name must be a non-blank string.'
);
}
$testArguments = \array_merge($this->data, $this->dependencyInput);
$this->registerMockObjectsFromTestArguments($testArguments);
try {
$testResult = $this->{$this->name}(...\array_values($testArguments));
} catch (\Throwable $exception) {
if (!$this->checkExceptionExpectations($exception)) {
throw $exception;
}
I didn't understand the syntax in this line:
$testResult = $this->{$this->name}(...\array_values($testArguments));
Can anyone explain me what the previous line means, please?
I forgot to ask another thing: what does mean ...\ before array_values?

Related

Trying to force an entry in an array to be an array

I am trying to create an associative array of associative arrays in gawk, and what I initially tried was:
options[key][subkey] = 1
However, when it got to this line, I unceremoniously received the error fatal: attempt to use scalar 'option["Declaration"]' as an array ("Declaration" being one of the main keys that my program uses, although I presume the exact value is irrelevant. At this particular point in the program, there was no "Declaration" entry assigned, although there were entries which had "Declaration" as a subkey on other entries, which may be meaningful).
So with a bit of googling, I found another stackoverflow question that looked like it answered my issue, so I put the following code immediately above it:
if (typeof(options[key])!="array") {
options[key] = 0;
delete options[key];
split("",options[key]);
}
However, this does not work either, instead now giving me the error: fatal: split: second argument is not an array
What am I doing wrong?
EDIT: Note, that I cannot use a basic 2-dimensional array here... for what I am doing, it is important that I am using one associative array to another because I need to be able to later identify the subkeys that were used on a given key.
Pursuant to requests below, I am posting the relevant functions that use the associative array, which may help clarify what is going on.
function add_concrete(key, concrete) {
if (key == concrete) {
return;
}
if (length(options[key])>0) {
for(i in options[key]) {
add_concrete(i, concrete);
}
}
contains[key][concrete] = 1
}
function add_options(name, value) {
subkey = trim(name);
if (subkey == "") {
return;
}
if (match(value, ";") > 0) {
exporting = 0;
}
split(value, args, /[ |;]*/);
for (i in args) {
key = trim(args[i]);
if (key != "") {
print("Adding " name " to " key);
options[key][subkey] = 1
if (concrete[key]) {
add_concrete(subkey, key);
}
}
}
}
Sorry, cooking at the same time. As you didn't post much, don't have much to work with, but with no "initialization":
$ awk 'BEGIN {
options[key] = 0;
delete options[key];
# options[key][1] # cant see me
split("",options[key]);
}'
awk: cmd. line:5: fatal: split: second argument is not an array
But with "initialization":
$ awk 'BEGIN {
options[key] = 0;
delete options[key];
options[key][1] # can see me
split("",options[key]);
}'
$_ # see this cursor happily blinking without any error

Fatal error: Can't use function return value in write context in

Fatal error: Can't use function return value in write context in /home4/tigas44/public_html/wp-content/themes/cardealer/includes/menus/menus.php on line 67
can be seen at:
http://firstnationsautomobileapproved.com/
which refers to the following line;
if(!isset($_COOKIE['cars']) || empty(json_decode($_COOKIE['cars']))) {
from the block:
$compareClass = "";
if(!isset($_COOKIE['cars']) || empty(json_decode($_COOKIE['cars']))) {
$compareClass = esc_attr(' style=display:none');
}
The empty() functions seems to be the cause of your issue. The documentation says the following:
Prior to PHP 5.5, empty() only supports variables; anything else will
result in a parse error. In other words, the following will not work:
empty(trim($name)). Instead, use trim($name) == false.
So try to change your code to this:
$compareClass = "";
if(!isset($_COOKIE['cars']) || json_decode($_COOKIE['cars']) == false) {
$compareClass = esc_attr(' style=display:none');
}

WordPress function get_row() doesn't work properly

I got problem with function get_row() in WordPress and can't find satisfied answer for my situation. That is a piece of my code
function take_category() {
$table_result = array();
$connect_to = connect_to_db();
$question = "select id_cat, name_cat from category";
if (!($result=$connect_to->get_results($question, ARRAY_N))) {
return false;
}
$prepared_row =$connect_to->prepare("%s", $question);
var_dump($prepared_row);
$row=$conntect_to->get_row($prepared_row, ARRAY_N, 1); // line 689
var_dump($row).'</br>';
for ($count=0; $row=$conntect_to->get_row($question, ARRAY_N, 1);
$count++) {
$table_result[$count] = $row;
.........
return $table_result;
this function is placed into functions.php. Function connect_to_db() is defined in this file as well:
function connect_to_db() {
global $wpdb;
$wpdb = new wpdb('****', '', '****store', 'localhost');
if (!$wpdb) {
return false;
} else{
$wpdb->query('SET autocommit = 1;');
return $wpdb;
}
}
Connection to Database is worked properly. Function prepare works correctly as well. This is var_dump($prepared_row):
string(39) "'select id_cat, name_cat from category'"
But next piece of code
$row=$conntect_to->get_row($prepared_row, ARRAY_N, 1); // line 689
var_dump($row);
shows result NULL: and fatal error
***Fatal error:** Uncaught Error: Call to a member function get_row() on
null in ....\functions.php:689 Stack trace: #0 ...\indeks.php(12):
take_category() #1 {main} thrown in ...\functions.php on line 689*
File indeks.php is a file where function take_category() is called:
$cat_table = take_category();
But if I changes my line 689 like this:
$row=$connect_to->get_row("select id_cat, name_cat from category",
ARRAY_N, 1);
I see var_dump($row):
array(2) { [0]=> string(1) "2" [1]=> string(9) "Textbooks" }
and the same fatal error!
What is wrong with function get_row?
Dear gentelments i found the problem. Sorry for waisting your time...
Should $conntect_to->get_row() not be $connect_to->get_row()?
Typo error in conntect_to-> and connect_to->. Use it carefully.
Variable is mispelled. You set $connect_to earlier. However now you are accessing $conntect_to. Rename it to $connect_to.

QHash cannot convert parameter 1 from 'class QHash<class QDomElement,class QDomElement>::const_iterator' to '::iterator'

I have a qhash defined with key value pair as QDomElement. as given below. I am trying to update the hash by using const_iterator. But while doing so below error is thrown, how to resolve the same:-
error C2664: 'erase' : cannot convert parameter 1 from 'class QHash<class QDomElement,class QDomElement>::const_iterator' to 'class QHash<class QDomElement,class QDomElemen
t>::iterator'
Code Snippet :-
// update parent child mapping hash
QHash<QDomElement, QDomElement>::const_iterator pList = hashParentChildList.constBegin();
while (pList != hashParentChildList.constEnd())
{
if(pList.key() == element)
{
pList = hashParentChildList.erase(pList); // Error Line
}
else
{
pList++;
}
}
}
Thanks,
Priyanka
Problem solved, use
QHash::iterator pList = hashParentChildList.begin();
instead of
QHash::const_iterator pList = hashParentChildList.constBegin();

Grid Group By Error

I tried group telerik grid using drop down list
grouping method source code is bellow
try
{
this.grd.MasterTableView.GroupByExpressions.Clear();//clear all group expressions
grd.MasterTableView.GroupsDefaultExpanded = false;
GridGroupByExpression expression = new GridGroupByExpression();
GridGroupByField gridGroupByField = new GridGroupByField();
gridGroupByField = new GridGroupByField();
if (cboGroupByItem1.SelectedValue != "0")
{
gridGroupByField.FieldName = cboGroupByItem1.SelectedValue;
gridGroupByField.HeaderText = cboGroupByItem1.SelectedItem.Text;
expression.SelectFields.Add(gridGroupByField);
}
if (cboGroupByItem2.SelectedValue != "0")
{
gridGroupByField.FieldName = cboGroupByItem2.SelectedValue;
gridGroupByField.HeaderText = cboGroupByItem2.SelectedItem.Text;
expression.SelectFields.Add(gridGroupByField);
}
grd.MasterTableView.GroupByExpressions.Add(expression);
}
catch (Exception ex)
{
label1.Text = ex.ToString();
}
finally
{
grd.Rebind();
}
when grid rebind method it will generate bellow error
An error occurred adding a relation to DataRelationCollection. Please,
make sure you have configured the expressions properly - both
GroupByFields and SelectFields are required!
How to solve this problem ?
You need to add this line after you add the gridGroupField to expression.
expression.GroupByFields.Add(gridGroupByField);
As the error message says, you need to add the fields you want to groupby.
If you have an aggregate field you dont have to add it to the expression as GroupByField, only as SelectFields.
Hope it helps.

Resources