How do I replace an assertion error message? If I call $this->assertTrue(false, 'message'), it will display both the string "message" and also another message stating that false is not true. How do I get it to only output the message that I chose? Is this even possible?
code-crutch which comes to my mind when I faced the same problem:
public function assertTrue($condition, $message = '')
{
if (!$condition) $this->fail($message);
}
With PHPUnit 6 you must have got one assertion at least, so i suggest a little edited #avolkov answer:
public function assertTrue($condition, $message = '')
{
if (!$condition){
$this->fail($message); //This will cause test fail with your message
}
else{
$this->anything(); //This will eliminate error which says that your test doesn't have assertion
}
}
It's not possible.
Why would you want to do so? Never encountered a case in which the default message is not helpful in any way. The custom message should add information, not replace the default one.
Related
I response this error when get JSON data by retrofit.
List<NewLicense> result = null;
Call<List<NewLicense>> serviceResult = ShahrdariApp.getShahrdariWebService().getLicenses(Configuration.getInstance().getString(SharedPrefs.MAC_ADDRESS), id);
try {
Response<List<NewLicense>> response = serviceResult.execute();
result = response.body();
Log.d("responseCode", String.valueOf(response.code()) );
} catch (Exception e) {
exceptionHandling(e);
Log.d("responseCode", String.valueOf(e.getMessage()) );
}
return result;
I had the same issue and forgot to set the Project SDK added this and it resolved the issue.
Simply restarting the IDE via File -> Invalidate caches can often solve this issue.
I faced the message
Unable to evaluate the expression Cannot find source class for
java.util.List
in hovering a List field while debugging in IntelliJ IDEA 2022.1.3 (UltimateEdition).
Even though an SDK was assigned to my Project, it helped to visit
IDEA ->File ->Project Structure -> Platform Settings ->SDKs and re-assign the SDK already visible in the list.
Namely I assigned openjdk-1.8.0.302-1, applied "OK", after that it was possible to debug a List foo.
IDE restart after that may additionally be necessary.
How can I write the two lines of code below into one line of code:
$service_review->user_id=\Auth::user();
$user_service->service_reviews()->save($service_review);
The reason being that the line including Auth::user() is throwing an error since it's a foreign key in my "service_reviews" table and so "DOESN'T HAVE A DEFAULT VALUE"
The problem is if I give precedence to:
\Auth::user()->service_reviews()->save($service_review);
Then in this case, the authorized user is fetched but my user_service_id now throws the error as "DOESN'T HAVE A DEFAULT VALUE".
The code of my store method (This is from my ReviewsController that is based on a Nested Route:
Route::resource("services.reviews", "ReviewsController"); is as follows:
public function store(ReviewsRequest $request, $id){
$service_review = new Service_review($request->all());
$user_service = User_service::findOrFail($id);
$service_review->user_id=\Auth::user();
$user_service->service_reviews()->save($service_review);
return redirect("reviews");
I reckon passing them in one line of code will solve this error.
Yes your're right #MinaAbadir
I ended up doing it as follows:
public function store(ReviewsRequest $request, $id){
$service_review = new Service_review($request->all());
$user_service = User_service::findOrFail($id);
$service_review->user_id = \Auth::user()->email;
$user_service->service_reviews()->save($service_review);
return redirect("reviews");
}
It seems calling the specific column you want retrieved negates the foreign key problem. Maybe MySQL figures out the relationship via Eloquent. Let me know if I can clean this up further.
Got a very weird problem.
I just successfully implemented a simple ajax validation on my site (Yey!). I hooked up the validation to the OnFocusOut event of every textbox via backcode, which runs perfectly.
The weird bug happens when,on the same page , I call the exact same method and pass the same parameters via a validate() method or add the attribute OnFocusOut on document.ready() . I keep getting a status of 500.
I was able to verify that the server side method isn't successfully called when using validate() but runs when OnFocusOut is triggered.
WebServiceAdapter
function ValueChanged(target, validationDiv,valueType) {
targetControl = document.getElementById(validationDiv);
// Added this part because I'm guessting a null is causing it
var str = (target.value === '') ? " " : target.value;
switch (valueType) {
case "email":
webServiceAdapter.EmailExist(str);
break;
case "screenName":
webServiceAdapter.ValidScreenName(str);
break;
case "changePassword":
webServiceAdapter.PasswordCorrect(str);
break;
}
Adding OnFocusOut backcode - WORKS
txtEmail.Attributes.Add("onfocusout", "ValueChanged(this,'"+Email.ClientID+"','email')");
Adding OnFocusOut jquery - DOES NOT WORK
$("#<%=txtEmail.ClientID%>").attr("onfocusout", "ValueChanged('<%=txtEmail.ClientID%>', '<%=Email.ClientID%>', 'email')");
Calling via validate() method - DOES NOT WORK
ValueChanged('<%=txtEmail.ClientID%>', '<%=Email.ClientID%>', 'email');
Edit:
I'm also getting this error "An error occurred: Invalid web service call, missing value for parameter: 'email'." After invoking validate()
Solved the problem.
Quite embarrassing really. It was a "common sense bug".
ValueChanged() was expecting an object as the first parameter - this is what the backcode is doing by using "this". For the call from validate(), i was using the ID.
I've created my own data transformer, as explained in the dedicated cookbook, here is my reverse transformation:
public function reverseTransform($val)
{
// ...
// My logic here
// ...
// If $val is not valid
throw new TransformationFailedException(
'My custom error message'
);
}
The question is: how do I get the "custom error message" thrown? I would like to display it as the error message of my form field. How do I do that?
Thanks!
Sort answer is: You don't. The transformers job is to, well, transform and not to do error checking.
Add a constraint to the field which will check the transformed value and take care of error messaging.
So I have a class where I instantiate a variable callback like so:
public var callback:Function;
So far so good. Now, I want to add an event listener to this class and test for existence of the callback. I'm doing like so:
this.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent) : void {
if (callback) {
// do some things
}
});
This works great, doesn't throw any errors, but everywhere I test for callback I get the following warning:
3553: Function value used where type Boolean was expected.
Possibly the parentheses () are missing after this function reference.
That bugged me, so I tried to get rid of the warning by testing for null and undefined. Those caused errors. I can't instantiate a Function as null, either.
I know, I know, real programmers only care about errors, not warnings. I will survive if this situation is not resolved. But it bothers me! :) Am I just being neurotic, or is there actually some way to test whether a real Function has been created without the IDE bitching about it?
Similar to using typeof:
if(callback is Function){
}
I believe should evaluate to true if the function exists and is a function and false if it is null or is not a function. (although if that doesn't work try if(callback && callback is function){}
if( !(callback == null)){
// do something
}
There's already an answer that works, but I thought I'd mention that you can also stop the warning from occurring by explicitly casting the result to a Boolean.
if (Boolean(callback)) {
// do something
}
Have you tried:
if (typeof callback == "function") {
// do some things
}
?
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/operators.html#typeof