How to implement a Tmar test in Jspresso? - jspresso

Following the www.tmar-test.com installation procedure, I wrote a very basic test (arithmetic sum) in my Jspresso application and all is OK.
In a second step, I would like to write a more realistic test and call a method that is part of my Jspresso application.
I need to initiate the test description context in order to call the method, but I lack of information.
Do you have a snippet to help me ?
As example, based on Hrsample, could you provide a Tmar method calling the computeAge method ?
Below the computeAge method :
package org.jspresso.hrsample.model.service;
import java.util.Date;
import org.jspresso.hrsample.model.Employee;
import org.jspresso.framework.model.component.service.IComponentService;
/**
* The services delegate of the Employee entity
*/
public class EmployeeServiceDelegate implements IComponentService {
/**
* Computes the employee age.
*
* #param employee
* the employee this service execution has been triggered on.
* #param birthDate
* a birth date (might be different than the actual employee birth
* date).
* #return the age computed from the birth date passed as parameter.
*/
public Integer computeAge(Employee employee, Date birthDate) {
if (birthDate != null) {
return new Integer(
(int) ((new Date().getTime() - birthDate.getTime()) / (1000L * 60 * 60 * 24 * 365)));
}
return null;
}
}

Look this post at Jspresso.org which should help you.

Related

API Platform & Symfony: what is the correct way to make a custom controller for collection operations?

As far as I understand, Api Platform deletes and updates one by one the resources of a Collection. For example, I have an Activity Entity, which has a Many-To-One relation with OpeningHours: if I want to delete or add multiples OpeningHours through an Admin Back Office, I must call a "delete" operation for each openingHour with its unique #id. As long as I have very few OpeningHours, it's quite all right : the job is done in a few seconds. But what am I supposed to do when I have thousand of them ? Just wait ?
So I've created a Custom Controller and a Custom Route - so far only for the Delete Operation ; the update operation will come after.
First Question : is this the right way to do it or have I missed something in the docs?
Here is my API configuration for the Activity Entity:
/**
* #ApiResource(
* collectionOperations={
* "get"={"normalization_context"={"groups"="activity:list"}},
* "post"={"denormalization_context"={"groups"="activity:post"}},
* },
* itemOperations={
* "get"={"normalization_context"={"groups"="activity:item"}},
* "put"={"denormalization_context"={"groups"="activity:item"}},
"delete_opening_hours"={
* "method"="DELETE",
* "path"="/admin/activity/{id}/delete_opening_hours",
* "controller"=DeleteOpeningHoursAction::class,
* "read"=false,
* },
* "delete", "patch"
* },
* attributes={"pagination_items_per_page"=10}
* )
And my Custom Controller :
/**
* Class DeleteOpeningHoursAction
* #Security("is_granted('ROLE_ADMIN')")
*/
final class DeleteOpeningHoursAction extends AbstractController
{
/**
* #Route(
* name="delete_opening_hours",
* path="/admin/activity/{id}/delete_opening_hours",
* methods={"DELETE"},
* )
*/
public function deleteHours(Activity $data):Activity
{
$em = $this->getDoctrine()->getManager();
$activity = $em->getRepository('App\Entity\Activity')->find($data);
$openingHours = $activity->getOpeningHours();
foreach ($openingHours as $hour) {
$em->remove($hour);
}
$em->flush();
$response = new Response();
$response->setStatusCode(204);
return $response;
}
}
It does the requested job: all the OpeningHours are deleted at once, but it returns a 500 Error:
Return value of App\Controller\Action\DeleteOpeningHoursAction::deleteHours() must be an instance of App\Entity\Activity, instance of Symfony\Component\HttpFoundation\Response returned
And if I return $activity instead of the response above, the error message becomes :
Return value of App\Controller\Action\DeleteOpeningHoursAction::deleteHours() must be an instance of Symfony\Component\HttpFoundation\Response, instance of App\Entity\Activity returned
So what am I doing wrong? What is the correct response for a Custom Controller?
I'm quite confused.
Thanks for any help.

ActiveJDBC , How can i query some columns i interest with in a single table

when i query a single table , i do not want all columns , i just want some column that i interest in.
For example, when i use where method to query a table, it will query all columns in a table like
public class SubjectSpecimenType extends Model {
}
SubjectSpecimenType.where("SUBJECT_ID = ? AND SITE_ID = ?", subjectId, siteId);
i don't know if there has a method named select that i can use to query some column like
SubjectSpecimenType.select("SUBJECT_NAME", "SITE_NAME").where("SUBJECT_ID = ? AND SITE_ID = ?", subjectId, siteId);
there are the source code in LazyList.java
/**
* Use to see what SQL will be sent to the database.
*
* #param showParameters true to see parameter values, false not to.
* #return SQL in a dialect for current connection which will be used if you start querying this
* list.
*/
public String toSql(boolean showParameters) {
String sql;
if(forPaginator){
sql = metaModel.getDialect().formSelect(null, null, fullQuery, orderBys, limit, offset);
}else{
sql = fullQuery != null ? fullQuery
: metaModel.getDialect().formSelect(metaModel.getTableName(), null, subQuery, orderBys, limit, offset);
}
if (showParameters) {
StringBuilder sb = new StringBuilder(sql).append(", with parameters: ");
join(sb, params, ", ");
sql = sb.toString();
}
return sql;
}
when call formSelect method, the second param columns always be null
is there a unfinish TODO ?
When operating on Models, ActiveJDBC always selects all columns, because if you load a model and it has partial attributes loaded, then you have a deficient model. The columns are specified in some edge cases, as in the RawPaginator: https://github.com/javalite/javalite/blob/e91ebdd1e4958bc0965d7ee99e6b7debc59a7b85/activejdbc/src/main/java/org/javalite/activejdbc/RawPaginator.java#L141
There is nothing to finish here, the behavior is intentional.

An Issue with automatic code documentation | PHP

I'm having a CodeIgniter project with lots of modules and codes residing in it.
Now I would like to create documentation for other new co-workers.
For example
/**
* inline tags demonstration
*
* This class generates bars using the main algorithm, which also
* works heavily with {#link foo()} to rule the world. If I want
* to use the characters "{#link" in a docblock, I just use "{#}link." If
* I want the characters "{#*}" I use "{#}*}"
*
* #author ahobbit
* #copyright middleearth.org XVII
* #version 1.2.3
*/
class bar
{
// beginning of docblock template area
/**##+
* #access private
* #var string
*/
var $_var1 = 'hello';
var $_var2 = 'my';
var $_var3 = 'name';
var $_var4 = 'is';
var $_var5 = 'Bob';
var $_var6 = 'and';
var $_var7 = 'I';
/**
* Two words
*/
var $_var8 = 'like strings';
/**##-*/
var $publicvar = 'Lookee me!';
}
/**
* Makes chocolate bars
*
* There are two aspects to this class.
* {#inheritdoc } In addition, the foo class
* makes the bars chocolate
*/
class foo extends bar
{
/**
* Check if a Sql row exists. (with two values)
*
* This function will check if a selected sql row exists that contains two
* known values.
*
* #param string $tblname Sql Table Name
* #param string $colname Sql Column Name 1
* #param string $value Sql value 1
* #param string $colname2 Sql Column Name 2
* #param string $value2 Sql value 2
* #return boolean returns true if the sql row does exist
*/
function tableHasRow2D($tblname, $colname, $value, $colname2, $value2) {
$row = sqlQuery("SELECT COUNT(*) AS count FROM $tblname WHERE " . "$colname
LIKE '$value' AND $colname2 LIKE '$value2'");
return $row['count'] ? true : false;
}
}
I had made use of with the following commands
I. PHPdoc
E:\xampp\htdocs\CI_Proj> php phpDocumentor.phar -d application
PHP Warning: count(): Parameter must be an array or an object that implements Countable in phar://E:/xampp/htdocs/CI_Proj/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1293
Execute transformation using writer "twig"
Execute transformation using writer "twig"
Execute transformation using writer "twig"
Execute transformation using writer "twig"
Execute transformation using writer "twig"
Execute transformation using writer "Graph"
Unable to find the `dot` command of the GraphViz package. Is GraphViz correctly installed and present in your path? 222.041s
Analyze results and write a report to log
.. 0.004s
II. ApiGen
E:\xampp\htdocs\CI_Proj\vendor\bin>apigen generate src "E:\xampp\htdocs\CI_Proj\application" --destination "E:\xampp\htdocs\CI_Proj\docs-apigen" --debug
Fatal error: Cannot use 'Object' as class name as it is reserved in E:\xampp\htdocs\CI_Proj\vendor\latte\latte\src\Latte\Object.php on line 14
ErrorException: Cannot use 'Object' as class name as it is reserved in E:\xampp\htdocs\CI_Proj\vendor\latte\latte\src\Latte\Object.php:14
Stack trace:
#0 [internal function]: Tracy\Debugger::shutdownHandler()
#1 {main}
Unable to log error: Logging directory is not specified.
Is it be possible to add comments to the modules before or after generation of code?
Since I'm looking to add comments to specific modules in the document itself and optionally that would
automatically inserted to the source code, at the right positions.
How should I need to manage the modules and code inside the project and How would I create a browsable HTML-Documentation?
Any other tool that makes generating the documentation directly from your PHP source code, that would be great in advice

Extending news Model does not work for FE and news_ttnewsimport

In order to upgrade an existing system, I have to import extended tt_news records to tx_news. The problem is, that the extending of the tx_news Model seems not to work proper and of course this, the import neither.
But in Backend I can see and store data in my additional fields.
What I've done so far:
I've extended tx_news Version 3.2.8
My Model:
class News extends \GeorgRinger\News\Domain\Model\News {
/**
* uidForeign.
*
* #var int
*/
protected $uidForeign;
/**
* Sets the uidForeign.
*
* #param int $uidForeign
*
* #return void
*/
public function setUidForeign($uidForeign)
{
$this->uidForeign = $uidForeign;
}
/**
* Returns the uidForeign.
*
* #return int $uidForeign
*/
public function getUidForeign()
{
return $this->uidForeign;
}
/**
* tableForeign.
*
* #var string
*/
protected $tableForeign;
/**
* Sets the tableForeign.
*
* #param string $tableForeign
*
* #return void
*/
public function setTableForeign($tableForeign)
{
$this->tableForeign = $tableForeign;
}
/**
* Returns the tableForeign.
*
* #return string $tableForeign
*/
public function getTableForeign()
{
return $this->tableForeign;
}
}
ext_localconf:
$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['classes']['Domain/Model/News'][] = 'news_extend';
I think that should work. The generated class in typo3temp seems correct. My fields including their getter/setter are in there.
But in Controller and FE I can not access these fields.
What am I missing? What else can I check?
If you upgrade a project, I don't know really the reason why you are using an old version of EXT:news.
What could be missing is the TCA definition of the field.
If you want to migrate from tt_news to news, there is a ready-to-use solution which can be found here https://github.com/ext-news/news_ttnewsimport
The reason was an configuration setting for the backend cache.
they have bees set to TYPO3\CMS\Core\Cache\Backend\NullBackend:class instead TYPO3\CMS\Core\Cache\Backend\NullBackend.
Now it works.

VSCode: How to document promise that resolves with complex object?

I have a function f that returns a Promise. The returned Promise either resolve({name: String, data: Object}) or reject(Error).
I've tried the following syntax(as mentioned in an issue in JSDoc) in VSCode, but it doesn't work:
/**
* #promise fPromise
* #reject {Error}
* #fulfill {Object} project
* #fulfill {Object} project.data
* #fulfill {String} project.name
* #returns fPromise
*/
I think your best bet is to wrap your fulfill response into a custom object:
/**
* #promise fPromise
* #reject {Error}
* #fulfill {Project}
* #returns {Promise.<Project>}
*/
function renderResults(data) {
return new Promise((resolve, reject) => {
resolve(new Project())
})
}
renderResults()
function Project() {
this.data = "data";
this.name = "project phoenix"
this.location = {
city: 'seattle',
state: 'wa'
}
}
This will show in VS Code like this:
To be as clear as possible, why not put the nature of the object on a single line for the description? Its just supposed to be a description of that fulfill.
/**
* #promise fPromise
* #fulfill {Object} A project object with the format {name: String, data: Object}
* #reject {Error}
* #returns fPromise
*/
Or, if you want to handle dynamically generated object keys, similar to the Google Style Guide:
/**
* #promise fPromise
* #fulfill {Object.<String, Object>}
* #reject {Error}
* #returns fPromise
*/
That allows anyone reading your comment to understand what the returned object looks like, what the keys are, and what type of value should be in each key.
Unless, you're trying to say that it can return any of the three possibilities. Then I think your original format is a little bit more descriptive of the possible results of the Promise being fulfilled.